wx.request POST情况下DATA数据结构被修改
发布于 5 年前 作者 licheng 11558 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现

在服务器不改变代码的情况下,GET和POST 的效果是一样的,因为wx.request文档上有一段话是这样说的:

data 参数说明

最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下:

  • 对于 GET 方法的数据,会将数据转换成 query string(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...

  • 对于 POST 方法且 header['content-type'] 为 application/json 的数据,会对数据进行 JSON 序列化

  • 对于 POST 方法且 header['content-type'] 为 application/x-www-form-urlencoded 的数据,会将数据转换成 query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)

  • 复现路径
  • 提供一个最简复现 Demo

参考demo程序:https://blog.csdn.net/weixin_39461487/article/details/80021420

以下是上传代码:

wx.request({

    url: app.serverInfo.address + ‘自己的服务器地址’,

    data: {

        //这里是服务器验证用户合法参数

        gps: point,//GPS数据数组

    },

    header: {

        “Content-Type”: “application/x-www-form-urlencoded”

    },

    dataType: “json”,

    method: “POST”,

    success: function (res) {

        console.log(“定位List上传成功”)

        console.log(res.data)

    }, fail: function (res){

        console.log(res)

    }

})

回到顶部