uni.request 请求中获取cookies内容,在安卓手机上无法获取!ios端是可以获取到的!
代码贴出来:
uni.request({
url: url,
data: params,
method: "POST",
dataType: 'json',
header: {
"content-type": "application/json",
"name": "true"
// // #ifdef APP-PLUS
// 'cookie': (sessionId ? sessionId : "") // 安全问题在浏览器端JS代码被禁止修改cookie
// // #endif
},
success: async (res) => {
let out: any = res;
let tokens: any = res.cookies;
console.log('cookies:',tokens)
console.log('Set-Cookies:',res.header['Set-cookie '])
console.log('返回的数据',res.header)
//存token todo 暂时注释
if (out.statusCode == 200 && out.cookies && out.cookies.length >= 1) {
let tokens: any = out.cookies[0].split(';')[0] + '; ' + out.cookies[1].split(';')[0] + ';' + out.cookies[2].split(';')[0];
uni.setStorageSync("sessionId", tokens);
console.log(tokens)
}
if (!out.data.success) {
//未登录授权
if (out.data.error && out.data.error.code == "ERR$UNAUTHORIZED") {
NToLogin();
resolve(out.data);
}
}
console.log(path,params,out.data)
resolve(out.data);
},
fail: (err) => {
console.log(path,params,'failed!!')
uni.showToast({
title: '网络异常,请重试',
icon: 'none',
});
uni.hideLoading();
reject(err);
}
})
运行截图:
无尘1
- 发布:2020-09-26 23:47
- 更新:2021-06-30 14:36
- 阅读:1739
uni.request 请求中获取cookies内容,在安卓手机上无法获取!
分类:uni-app