小程序的get和post请求头的区别
小程序在使用wx.request()接口 时 header 请求头默认是这样的
wx.request({
  url: 'test.php', //仅为示例,并非真实的接口地址
  data: {
     x: '' ,
     y: ''
  },
  header: {
      'content-type': 'application/json' // 默认值
  },
  success: function(res) {
    console.log(res.data)
  }
})
当然如果没设置请求类型是能请求到数据的,但是如果设置为POST请求,再使用 'content-type': 'application/json' // 默认值 就坑爹了,这样是请求不到想要的数据的。此时要更改请求头
wx.request({
  url: 'test.php', //仅为示例,并非真实的接口地址
  data: {
     x: '' ,
     y: ''
  },
  method:"POST",
  header: {
       "Content-Type": "application/ x - www - form - urlencoded" //post请求设置
  },
  success: function(res) {
    console.log(res.data)
  }
})
这样就能成功请求到数据了。
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号