支付宝小程序的post请求:
my.request({url: url,method: 'POST',data: {'isv_code':'440720252','device_sn':'11'},headers:{'content-type':'application/json',//默认值},dataType: 'json',success: function(res) {console.log(res)my.alert({content: 'success'});},fail: function(res) {my.alert({content: 'fail'});},complete: function(res) {my.hideLoading();my.alert({content: 'complete'});}});
最初我的post请求传参,后台怎么都接收不到。后来把headers默认的值换成了如下内容,划重点了:
"Content-Type"中的C千万
要大写!要大写!要大写!
headers:{"Content-Type": "application/x-www-form-urlencoded"},
这个方法同样也适用于微信小程序
wx.request({url: 'https://xxx',data: {'code': '123'},method: 'POST',header: {"Content-Type": "application/x-www-form-urlencoded"},success: function (res) {},fail: function (err) {}})