标签:string turn header 不能 log 发送 ret default module
<script>
const stream = weex.requireModule(‘stream‘);
const storage = weex.requireModule(‘storage‘)
// const jbtoken = storage.getItem("teacherToken",(res)=>{ return res.data})
// 如果你需要通过 POST 发送 json 数据, 需要将 Content-Type 设为 application/json。
let get = function(url,token){
return new Promise( function(resolve,reject ) {
stream.fetch({
method: ‘get‘,
// timeout: 30000,//30s
url:url,
type: "json",
headers: {"Content-Type":"application/json","token":token}
}, function(ret){
if(!ret.ok){
let err = new Error(‘请求失败‘)
reject(err);
}else{
resolve(ret.data);
}
})
});
}
let post = function({url,token=null,param={}}){
return new Promise( function(resolve,reject ) {
stream.fetch({
method: ‘post‘,
// timeout: 30000,//30s
url:url,
type: "json",
headers:{"Content-Type":"application/json","token":token},
// 参数是字符串 不能发送json
body: JSON.stringify(param)
}, function(ret){
// console.log(ret)
if(!ret.ok){
let err = new Error(‘请求失败‘)
reject(err);
}else{
resolve(ret.data);
}
})
});
}
export default {
get,
post
}
</script>
标签:string turn header 不能 log 发送 ret default module
原文地址:https://www.cnblogs.com/pyx-blog/p/12194926.html