微信小程序wx.request POST请求,请求参数需要form-data形式

正常情况下,我们的请求参数一般都默认在 Request Payload 中


但是有些时候,你的后端就需要在 Form Data 中,

解决方案:

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

wx.request({
  url: 'api/test', 
  data: {
    x: '',
    y: ''
  },
  header: {
    'content-type': 'application/x-www-form-urlencoded' //修改此处即可
  },
  success (res) {
    console.log(res.data)
  }
})

修改后,请求参数就到Form Data中了

posted @ 2022-11-08 16:39  清和时光  阅读(2676)  评论(0)    收藏  举报