[英]React Axios get call doesn't work with authorization header
我正在研究需要授權的 Axios 參與反應。 在我添加授權之前,它運行良好,在我在后端和前端添加授權 header 之后,它有 CORS 錯誤。 我在 postman 中嘗試了 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)
}
);
})
}
我自己關閉了這個帖子。 因為我犯了一個拼寫錯誤,應該是
headers:{
'Authorization': AuthStr
}
希望它對其他人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.