AXIOS:发送授权标题返回错误401,授权标头丢失
问题描述:
我来到了this解决方案,但这不适用于我。AXIOS:发送授权标题返回错误401,授权标头丢失
以下是我的代码:
axios.post('http://myurl/api/login', {
email: '[email protected]',
password: '123456'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(response => {
if (response.data) {
this.AuthToken = response.data.token
console.log(this.AuthToken)
axios.get('http://myurl/userdetails/:uid', {
uid: 'D123'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': this.AuthToken
}
}).then(response => {
if (response.data) {
// this.AuthToken = response.data
console.log(response.data)
}
}).catch(error => {
console.log('User Data response Error: ' + error)
})
}
}).catch(error => {
console.log('Login Error: ' + error)
})
我从第一个POST登录API调用获得令牌。我用那个toke作为身份验证令牌传递给另一个API调用。但我得到错误:缺少授权标头
答
找到了解决办法:
axios.defaults.headers.common['Authorization'] = this.AuthToken;
答
尝试添加另一个标头。 “Access-Control-Allow-Headers”:“*”。
+0
试过但没有工作。 –
您是否尝试过在令牌前添加“承载”? https://security.stackexchange.com/q/108662 – Bert
是的,我之前尝试过,但没有运气。 –