使用uni-app开发钉钉小程序时,uni.request()中传入的参数为JSON格式时的注意事项:
1、使用JSON.stringify(params)把对象转换为JSON格式
2、必须得添加请求头:
header: {
'content-type': 'application/x-www-form-urlencoded'
}
完整代码:
const getData = uni.request({
url: '网络请求地址',
method: "POST", //方法
data: {
Params:JSON.stringify(data), //对参数进行转换
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: (res)=> {
console.log("成功",res);
},
fail:(err)=> {
console.log(("失败",err))
}
});