我正在开发一个简单的nodejs应用程序。我正在尝试从该应用程序进行REST API调用,REST API具有基本身份验证。我得到错误“ERRORError:getaddrinfo ENOTFOUND”尝试使用stackoverflow中建议的选项,但无法使其工作。任何人都可以请帮我this..Here是我使用`从节点调用第三方休息api
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);
});
感谢代码提前
问候
VHC
可能重复的[Node.js getaddrinfo ENOTFOUND](http://stackoverflow.com/questions/17690803/node-js-getaddrinfo-enotfound) – ThomasThiebaud
托马斯..我已经尝试了所有可能的方式,我发现在stackoverflow .. 。我无法ping通..我尝试ping www.google.com。为所有ping获取连接超时错误 – user1948228
您能分享网址吗? – ThomasThiebaud