Axios post 未授权错误但 curl 有效

Axios post unauthorized error yet curl works

试图通过 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)
    });

我的可用问题 returns JSON 正确卷曲,而我的 axios 调用 returns 错误

{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)
    });