来自 Node.js 的 HTTP 请求的 getaddrinfo ENOENT 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15527775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getaddrinfo ENOENT error from HTTP request on Node.js
提问by theGreenCabbage
Below is the code for my Node.js HTTP response requester.
下面是我的 Node.js HTTP 响应请求者的代码。
Once I use a website that I explicitly know does not exist, the error message would notify me the error: getaddrinfo ENOENT
一旦我使用我明确知道不存在的网站,错误消息就会通知我错误: getaddrinfo ENOENT
I want to know more about this error. What spawns it? What's the detail of the error? Would 404' spawn it?
我想了解更多关于这个错误的信息。什么产生它?错误的细节是什么?404'会产生它吗?
var hostNames = ['www.pageefef.com'];
for (i; i < hostNames.length; i++){
var options = {
host: hostNames[i],
path: '/'
};
(function (i){
http.get(options, function(res) {
var obj = {};
obj.url = hostNames[i];
obj.statusCode = res.statusCode;
// obj.headers = res.headers;
console.log(JSON.stringify(obj, null, 4));
}).on('error',function(e){
console.log("Error: " + hostNames[i] + "\n" + e.message);
});
})(i);
};
回答by user568109
You can do this to get more details about error.
您可以执行此操作以获取有关错误的更多详细信息。
.on('error',function(e){
console.log("Error: " + hostNames[i] + "\n" + e.message);
console.log( e.stack );
});
If you give a non-existent url then above code returns :
如果您提供一个不存在的网址,则上述代码返回:
getaddrinfo ENOTFOUND
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
The error is thrown from http.ClientRequest class by http.request(). No a 404 will not generate this error. Error 404 means that the client was able to communicate with the server, but the server could not find what was requested. This error means Domain Name System failed to find the address (dns.js is for NAPTRqueries).
该错误是由 http.request() 从 http.ClientRequest 类抛出的。否 404 不会产生此错误。错误 404 表示客户端能够与服务器通信,但服务器找不到请求的内容。此错误表示域名系统无法找到地址(dns.js 用于NAPTR查询)。

