微信小程序wx.request POST获取不到数据解决办法

get

    //发起请求

    wx.request({
      url: 'http://www.xiaochengxu.com/home/index/curd', //仅为示例,并非真实的接口地址
      method:'GET',
      data: {
        title: '123',
        content: '456'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
      }
    })
 
 
post
    //发起请求
    wx.request({
      url: 'http://www.xiaochengxu.com/home/index/curd', //仅为示例,并非真实的接口地址
      method:'POST',
      data: {
        title: '123',
        content: '456'
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data)
      }
    })
 
解决办法:修改headder里面的属性值。

猜你喜欢

转载自www.cnblogs.com/qcjdp/p/11274879.html
今日推荐