I'm trying to use axios for a GET request with an API which requires an Authorization
header.
My current code:
const AuthStr = 'Bearer ' + USER_TOKEN;
where USER_TOKEN
is the access token needed. This string concatenation may be the issue as if I post this as AuthStr = 'Bearer 41839y750138-391'
, the following GET request works and returns the data I'm after.
axios.get(URL, { 'headers': { 'Authorization': AuthStr } })
.then((response => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
I also tried setting this as a global header with no success.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…