关于微信小程序POST请求

2018-12-21 08:37:00  卢浮宫  版权声明:本文为站长原创文章,转载请写明出处


一、背景

    今天在做微信小程序时由于get请求无法达成预期,所以需要使用post请求,查了资料,记录如下。


二、相关操作

    ①需要在wx.request中表明使用方法  method:POST

    ②需定义请求头为 "Content-Type": "application/x-www-form-urlencoded"


二、核心代码如下



    wx.request({
url: "your url",
method: "POST",
data: {
params: JSON.stringify(params)
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success(res) {
console.log(res);
if (!res.data.success) {
wx.showToast({
title: "操作失败!",
})
}
}
})




更多精彩请关注guangmuhua.com


最新评论: