来自Nodejs服务器的基本身份验证请求

时间:2018-05-16 17:04:00

标签: node.js http httprequest basic-authentication http-basic-authentication

到目前为止,我已在终端中使用此命令向readme.io api发出GET请求

curl https://dash.readme.io/api/v1 -X GET -u API_KEY:

PASSWORD VALUE为空,curl命令在终端中正常工作。

如何使用node.js执行此操作 我有这个。

const options = {
    method: 'GET',
    headers: {
        'Authorization': 'Basic API_KEY:'
    }
};

fetch('https://dash.readme.io/api/v1', options)
  .then(res => res.text())
  .then(body => console.log(body))
  .catch(err => console.log('ERROR', err))

但它返回:

{"error":"Unauthorized","errors":null}

你能否告诉我,我错误的是哪一部分?

提前致谢。

0 个答案:

没有答案