使用阿里云网关api进行数据的请求

1.在node项目中 install 需要的包

npm install aliyun-api-gateway -S

2.添加完成后根据官方文档进行编辑client端上代码(前提是在阿里云网关部分已经设置好了相关的网管api内容,这边只讲述前端进行调用的部分)

export async function post(url,data,callBack) {

    var result = await client.post(url, {
        data:data,
        timeout: 5000, // 5s
        headers: {
            accept: 'application/json',
            'content-type':'application/x-www-form-urlencoded'
        },
        signHeaders: {
            'x-ca-stage': 'TEST'
        },
    });


    if(result.errcode==1){
        //请求成功
        callBack(result);
    }

}

3.调用 data==>请求的body数据

post('请求的url', data,(res)=>{
       console.log(res.data)
   }).catch((err) => {
       console.log(err.stack);
   });

猜你喜欢

转载自blog.csdn.net/web_1993/article/details/80784917