微信小程序 wx.request POST方式提交数据,后台接收不到数据

一开始的代码是: 

wx.request({
  url: serverUrl+'/user/register',
  method: 'post',
  data: {
    'userName': userName
  },
  success: function(res){
    console.log(res);
  }
});

发现后台根本接收不到数据,最后发现要修改一下请求头信息: 


  header: {
    'content-type': 'application/x-www-form-urlencoded'
  },

只要在请求中加入上面的代码即可 

wx.request({
  url: serverUrl+'/user/register',
  method: 'post',
  data: {
    'userName': userName
  },
  header: {
    'content-type': 'application/x-www-form-urlencoded'
  },
  success: function(res){
    console.log(res);
  }
});

猜你喜欢

转载自blog.csdn.net/qq_37776015/article/details/91488197