小程序通過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)
}
})