服务器接收不了微信小程序的数据
时间:2020-01-14 21:35:51
收藏:0
阅读:121
使用primose封装微信小程序
发送数据给服务器,服务器接收不了数据 -为空,
之前header:{
// ‘content-type‘: ‘application/json‘, // 默认值
}改为
header: {
‘content-type‘: ‘application/x-www-form-urlencoded‘,
},
就没有问题了。
wx.request({
url: url,
method: method ? method : ‘GET‘,
header: {
‘content-type‘: ‘application/x-www-form-urlencoded‘,
},
data:data.data,
success: function (res) {
if (res.statusCode < 500) {
resolve(res.data)
} else {
showError()
reject(res.data)
}
},
其中原因:官网:
- 对于
POST
方法且header[‘content-type‘]
为application/json
的数据,会对数据进行 JSON 序列化 - 对于
POST
方法且header[‘content-type‘]
为application/x-www-form-urlencoded
的数据,会将数据转换成 query string(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)
原文:https://www.cnblogs.com/wen-/p/12194011.html
评论(0)