解決的問題
1、釘釘小程序的post請求如何發起
httpReq(msg, url, method, data) { // 再次封裝請求
return new Promise(function(resolve, reject) {
dd.showLoading({
content: msg
});
dd.httpRequest({
url: url,
method: method,
headers:{"Content-Type":"application/json"},
data: JSON.stringify(data),
success: (res) => {
dd.hideLoading();
if (res.status == 200) {
resolve(res);
} else {
reject(res);
}
},
fail: () => {
reject();
}
});
});
}
調用
this.httpReq('登錄中...','http://localhost:8081/beauty/login','post',{requestAuthCode: "0909"})
或者
this.httpReq('登錄中...','http://localhost:8081/beauty/login','post',{requestAuthCode: res.authCode})
2、請求數據格式定義
headers:{“Content-Type”:“application/json”}
注意放的位置啊,放method下面吧
3、請求數據轉成json
data: JSON.stringify(data)