首页 > 微信 > 详细

服务器接收不了微信小程序的数据

时间:2020-01-14 21:35:51      阅读:121      评论:0      收藏:0      [点我收藏+]
使用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)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!