React Axios 获取调用不适用于授权 header
React Axios get call doesn't work with authorization header
我正在研究需要授权的 Axios get in react。
在我添加授权之前,它很好用,我在后端和前端添加授权header后,它有CORS错误。我在邮递员中尝试了 get 调用,它非常有效。所以我认为应该是Axios在前端获取代码。
这是 Axios 获取代码:
async sendGetRequest(variable) {
return new Promise((resolve, reject) => {
let AuthStr = 'token';
console.log(typeof(AuthStr)); => the type is String
Axios.get(`url/${variable}`,{
header:{
'Authorization': AuthStr
}
})
.then(res => {
resolve(res.data)
}
);
})
}
我不确定它是否有误,对我来说看起来不错。
这是我的邮递员结果。(我隐藏了 url)
我自己关闭了这个post。
因为我打错了
应该是
headers:{
'Authorization': AuthStr
}
希望对其他人有所帮助。
我正在研究需要授权的 Axios get in react。 在我添加授权之前,它很好用,我在后端和前端添加授权header后,它有CORS错误。我在邮递员中尝试了 get 调用,它非常有效。所以我认为应该是Axios在前端获取代码。 这是 Axios 获取代码:
async sendGetRequest(variable) {
return new Promise((resolve, reject) => {
let AuthStr = 'token';
console.log(typeof(AuthStr)); => the type is String
Axios.get(`url/${variable}`,{
header:{
'Authorization': AuthStr
}
})
.then(res => {
resolve(res.data)
}
);
})
}
我不确定它是否有误,对我来说看起来不错。
这是我的邮递员结果。(我隐藏了 url)
我自己关闭了这个post。 因为我打错了 应该是
headers:{
'Authorization': AuthStr
}
希望对其他人有所帮助。