微信小程式傳送POST請求時後臺獲取不到傳輸的資料
阿新 • • 發佈:2019-01-04
在使用微信小程式傳送POST請求時,請求成功了,但是後臺獲取不到前端傳遞的資料;
按照官方文件,請求程式如下
var data={ code:res.code, commId:this.data.commInfo.id, commCount:this.data.commCount }; wx.request({ url: '請求地址', method:"POST", data:data, dataType:"json", success:(res)=>{ console.log(res); }, error(err) { wx.showToast({ title: '網路請求錯誤,錯誤資訊:' + err, }) } })
之後,在請求引數中設定請求頭如下,資料就能成功獲取
header: {"Content-Type": "application/x-www-form-urlencoded"},