小程序GET请求在小程序开发工具里直接就有简介,但POST还是找了一下才找到,权当自己记录用,不喜勿喷!话不多说,直接上代码:
wx.request({
url: 'http://www.dnwfb.com', // 仅为示例,并非真实的接口地址
method: 'post',
data: {
//所需要参数
//其中that.data.username是在wx.request请求外就写好的数据 that.data.password也一样
username: that.data.username,
password: that.data.password
},
//请求头 注:在get请求中可有可无,但post需要
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success(res) {
console.log(res.data)
}
})
本文链接:https://www.dnwfb.com/1557.html,转载请注明出处。
评论0