【发布时间】:2017-11-23 21:15:13
【问题描述】:
我找到了this 解决方案,但这对我不起作用。
以下是我的代码:
axios.post('http://myurl/api/login', {
email: 'john@doe.com',
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 调用中获取令牌。我使用该令牌作为身份验证令牌传递给另一个 API 调用。但我收到错误:缺少授权标头
【问题讨论】:
-
您是否尝试在令牌前添加“Bearer”? security.stackexchange.com/q/108662
-
是的,我以前试过这个,但没有运气。
标签: vue.js authorization axios