小程序通过wx.request()使用post方式传参
遇到的坑:打开调试器发现传参格式为json形式,
而服务器端想要的数据格式为
因此,需要在header中添加 "content-type": "application/x-www-form-urlencoded",便可以正常传参。
post示例:
wx.request({
url: '/api/test',
method:'post',
data: {code:code},
header: {
'content-type': 'application/x-www-form-urlencoded',
'csrf-csrf': 'csrf-csrf'
},
success: function (res) {
console.log(res)
}
})