
- 发布:2020-07-14 14:22
- 更新:2020-07-14 14:22
- 阅读:1321
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows10
HBuilderX类型: 正式
HBuilderX版本号: 2.8.0
手机系统: 全部
手机系统版本号: Android 10
手机厂商: 华为
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
const httpRequest = (opts) => {
let httpDefaultOpts = {
url: baseUrl+opts.url,
data: {
jsonrpc: "2.0",
method: "call",
params: opts.params || {},
id: Math.floor(Math.random() * 1000 * 1000 * 1000)
},
method: opts.method,
header: opts.method == 'get' ? {
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
} : {
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
'Content-Type': 'application/json; charset=UTF-8'
},
dataType: 'json',
}
let promise = new Promise(function(resolve, reject) {
uni.request(httpDefaultOpts).then(
(res) => {
if(res[1].header.authorization){
console.log(res[1].header.authorization)
uni.setStorage({
key:'token',
data:res[1].header.authorization
})
}
resolve(res[1].data.result)
}
).catch(
(response) => {
reject(response)
}
)
})
return promise
};
const httpRequest = (opts) => {
let httpDefaultOpts = {
url: baseUrl+opts.url,
data: {
jsonrpc: "2.0",
method: "call",
params: opts.params || {},
id: Math.floor(Math.random() * 1000 * 1000 * 1000)
},
method: opts.method,
header: opts.method == 'get' ? {
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
} : {
'X-Requested-With': 'XMLHttpRequest',
"Accept": "application/json",
'Content-Type': 'application/json; charset=UTF-8'
},
dataType: 'json',
}
let promise = new Promise(function(resolve, reject) {
uni.request(httpDefaultOpts).then(
(res) => {
if(res[1].header.authorization){
console.log(res[1].header.authorization)
uni.setStorage({
key:'token',
data:res[1].header.authorization
})
}
resolve(res[1].data.result)
}
).catch(
(response) => {
reject(response)
}
)
})
return promise
};
操作步骤:
获取后端返回的authorization值,在H5上面是可以获取到的,但是在app却读取不到authorization值,读取的值是undefined
获取后端返回的authorization值,在H5上面是可以获取到的,但是在app却读取不到authorization值,读取的值是undefined
预期结果:
在H5上面是可以获取到的,但是在app却读取不到authorization值,读取的值是undefined
在H5上面是可以获取到的,但是在app却读取不到authorization值,读取的值是undefined
实际结果:
希望app也能读取authorization
希望app也能读取authorization
bug描述:
获取后端返回的authorization值,在H5上面是可以获取到的,但是在app却读取不到authorization值,读取的值是undefined
0 个回复