[英]git api returning 401 unauthorized error when doing axios call but curl returns 200
axios call to git api returns 401, but curling the same url with the same headers returns 200 with the correct data, anybody know why?
let headers = {
"Authorization": "token abc",
"Accept" : "application/json",
"Content-Type": "application/json"
}
await axios.get("SOME_GIT_API_URL", headers)
.then((data) => {
console.log(data.data)
})
.catch((err) => {
console.log(err)
})
curl --location --request GET "SOME_GIT_API_URL" --header 'Authorization: token abc'
在 axios 上,header 密鑰必須在 object 內。 您的 header 變量不包括該“標題”作為鍵。 例子:
// header inside an object
const headerObject = {
header: {
"Authorization": "token abc",
"Accept" : "application/json",
"Content-Type": "application/json"
}
}
await axios.get("SOME_GIT_API_URL", headerObject)
.then((data) => {
console.log(data.data)
})
.catch((err) => {
console.log(err)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.