飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//发起网络请求
          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即可。

posted on 2018-02-22 12:02  飞狐爷  阅读(1090)  评论(0编辑  收藏  举报