试图通过axios来访问YouTrack的API,但我收到了未经授权的错误,而通过curl工作却产生了相同的参数。
卷曲:
curl -X GET \
'https://<my youtrack url>/api/issues' \
-H 'Authorization: Bearer perm:<my token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json'
axios:
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: ""}
谢谢
答案 0 :(得分:6)
将配置发送为第二个参数,因为GET请求不需要正文
axios.get('https://<my youtrack url>/api/issues', config)
.then((response) => {
console.log(response.data);
})
.catch(e => {
console.log('Error: ', e.response.data)
});