小程序post请求

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:07   17   0

小程序的post请求

https://developers.weixin.qq.com/miniprogram/dev/api/wx.request.html


这个请求头是必须的 POST请求
header: {
'content-type': 'application/x-www-form-urlencoded',
},
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)...)

var api = '';
wx.request({
      url: api,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        uid: that.data.id,
      },
      success(res) {
        that.setData({
          info: res.data.result,
        })
      }
    })

转载于:https://www.cnblogs.com/zelzzz/p/10544767.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP