网络通信
https://developers.weixin.qq.com/ebook?action=get_post_info&docid=000ee27c9c8d98ab0086788fa5b00a
4.4 发起 https 网络通信
小程序经常需要往服务器传递数据或者从服务器拉取信息,
这个时候可以使用wx.request这个API。
wx.request({
url: 'https://test.com/getinfo',
success: function(res) {
console.log(res)// 服务器回包信息
}
})
向服务器发送请求有两种方法
get, 发送给服务器的数据在 url 里
post, 发送给服务器的数据在 wx.request 的 data 参数里
url 长度有限制,所以一般用 post 方法
传送复杂数据时用 JSON 格式更合适, header 要做设置
header: { ‘content-type’: ‘application/json’},文章来源:https://www.toymoban.com/news/detail-853005.html
wx.request详细参数
具体见
https://developers.weixin.qq.com/ebook?action=get_post_info&docid=000ee27c9c8d98ab0086788fa5b00a文章来源地址https://www.toymoban.com/news/detail-853005.html
参数名 | 类型 | 描述 |
---|---|---|
url | String | 服务器接口, 只有这一项需要必填 |
data | Object/String | 请求的参数< |
到了这里,关于微信小程序网络通信的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!