[英]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? 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'
On axios, header key must be inside the object.在 axios 上,header 密钥必须在 object 内。 Your header variable not included that 'header' as key.您的 header 变量不包括该“标题”作为键。 Example:例子:
// 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.