码迷,mamicode.com
首页 > 其他好文 > 详细

小程序的get和post请求头的区别

时间:2017-10-13 00:46:07      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:div   pos   请求头   header   ons   类型   size   区别   logs   

小程序在使用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)
  }
})

 

  这样就能成功请求到数据了。

 

 

 

小程序的get和post请求头的区别

标签:div   pos   请求头   header   ons   类型   size   区别   logs   

原文地址:http://www.cnblogs.com/onelazycat/p/7658797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!