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

时间:2022-08-02 03:54:00

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里面的属性值。