【发布时间】:2022-01-04 14:04:13
【问题描述】:
我正在尝试使用基本身份验证向 Web url 发出获取请求。但它因连接问题而失败。
注意:当我使用 'request' 库而不是 'got' 时它可以工作
我在这里错过了什么?
const got = require('got');
(async () => {
try {
const res = await got(
{
url: 'https://httpbin.org/anything',
headers: {
Accept: 'application/json'
//Authorization: 'Basic abcjghgh8****'
}
})
console.log('statusCode:', res.statusCode);
console.log('body:', res.body);
} catch (error) {
console.log('error:', error);
}
})();
输出:
图书馆
【问题讨论】:
标签: javascript node.js api rest node.js-got