小程序wx.request POST请求,请求参数需要formdata形式

只要将wx.request的header中改为 ‘content-type’: ‘application/x-www-form-urlencoded’ 请求参数自然就变成了form-data形式

wx.request({
  url: 'test.php', //仅为示例,并非真实的接口地址
  data: {
    x: '',
    y: ''
  },
  header: {
    'content-type': 'application/x-www-form-urlencoded' //修改此处即可
  },
  success (res) {
    console.log(res.data)
  }
})

内容搬运来源:https://blog.csdn.net/weixin_44777433/article/details/103277495?spm=1001.2014.3001.5501

!!亲测有效

原文地址:https://www.cnblogs.com/liuqingxia/p/15793331.html