【微信小程序遇到的坑】使用post方式傳參

小程序通過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)
            }
          })
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章