标签: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) } })
这样就能成功请求到数据了。
标签:div pos 请求头 header ons 类型 size 区别 logs
原文地址:http://www.cnblogs.com/onelazycat/p/7658797.html