//发起网络请求 wx.request({ url: app.globalData.requestUrl_pay, data: { code: res.code }, method: "POST", header: { 'Content-Type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res) } })
wx.request post 的 content-type 默认为 'application/json'
服务器端只能使用如下方式接收参数:
$user_code = file_get_contents('php://input', 'r'); $user_code= json_decode($user_code,true); $code=$user_code['code'];
或者$HTTP_RAW_POST_DATA
如果服务器没有用到 json 解释的话,可以把 content-type 设置回 urlencoded。
wx.request({
....
method: "POST",
header: {
"content-type": "application/x-www-form-urlencoded"
},
...
})
终于可以post提交了,大家不要按照官网的文档写,也不用转格式,修改header即可。