export const HttpRequest = (url, data, method) => {
let header = ""
if (method == "POST") {
//header = "'content-type': 'application/json;charset:utf-8'"
header = "'content-type': 'application/x-www-form-urlencoded'"
} else {
header = ""
}
return new Promise((resolve, reject) => {
let urls = BASE_URL + url
// console.log("地址", urls)
uni.request({
url:urls.replace (/\s*/g,"") ,
method: method || 'GET',
data: data || {}, //对于'content-type': 'application/json;charset:utf-8'
//data:data, //对于'content-type': 'application/x-www-form-urlencoded'
header: {
header,
},
success: (res) => {
resolve(res)
},
//请求失败
fail: (err) => {
reject(err)
}
})
})
}
调用代码:
var code=e.detail.code;
var data={code:code};
//var data="code="+code;
HttpRequest("/wechat/weixin/getPhoneNumber/hznev",data,"POST");