![](/img/trans.png)
[英]Curl works but corresponding HttpConnection POST request fails as 400 error
[英]Axios post unauthorized error yet curl works
試圖通過axios嘗試使用YouTrack的API,但我收到了未經授權的錯誤,同時通過卷曲工作獲得相同的參數。
卷曲:
curl -X GET \
'https://<my youtrack url>/api/issues' \
-H 'Authorization: Bearer perm:<my token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json'
愛可信:
const config = {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer perm:<my token>'
},
responseType: 'json',
};
axios.get('https://<my youtrack url>/api/issues', {}, config)
.then((response) => {
console.log(response.data);
})
.catch(e => {
console.log('Error: ', e.response.data)
});
curl正確返回我可用問題的JSON,而我的axios調用返回錯誤
{error: "Unauthorized", error_description: ""}
謝謝
發送配置作為第二個參數,因為GET請求不需要正文
axios.get('https://<my youtrack url>/api/issues', config)
.then((response) => {
console.log(response.data);
})
.catch(e => {
console.log('Error: ', e.response.data)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.