【发布时间】:2017-02-14 15:52:21
【问题描述】:
我正在开发一个简单的 nodejs 应用程序。我正在尝试从该应用程序进行 REST API 调用,并且 REST API 具有基本身份验证。我收到错误 "ERRORError: getaddrinfo ENOTFOUND" 尝试使用 stackoverflow 中建议的选项,但无法使其工作。任何人都可以帮我解决这个问题。这是我正在使用的代码`
var http = require('http');
var url = 'someurl';
var username = 'username';
var password = 'password';
var optionsget = {
host: 'someurl',
method: 'GET',
auth: username + ':' + password,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
};
console.log('Do the GET call');
// do the GET request
var reqGet = http.get(optionsget, function(res) {
console.log("Hii");
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
console.info('GET result:\n');
process.stdout.write(d);
console.info('\n\nCall completed');
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error("ERROR" +e);
});
提前致谢
问候
录像机
【问题讨论】:
-
thomas .. 我已经尝试了在 stackoverflow 上找到的所有可能的方法...我也无法 ping 通..我尝试 ping 通 www.google.com 。获取所有 ping 的连接超时错误
-
可以分享一下网址吗?
-
您传递的实际网址是什么?它是一个完全限定的 URL,例如
http://somedomain.com/somepath?
标签: node.js rest http basic-authentication