节点上HTTP请求的getaddrinfo ENOENT错误。js(复制)

时间:2022-03-17 15:28:28

This question already has an answer here:

这个问题已经有了答案:

Below is the code for my Node.js HTTP response requester.

下面是我的节点的代码。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);
};

1 个解决方案

#1


8  

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 :

如果您给出一个不存在的url,那么上面的代码返回:

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 NAPTR queries).

错误从http抛出。由http.request ClientRequest类()。没有一个404不会产生这个错误。错误404意味着客户端能够与服务器通信,但是服务器无法找到所请求的内容。这个错误意味着域名系统找不到地址(dns)。js用于NAPTR查询)。

#1


8  

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 :

如果您给出一个不存在的url,那么上面的代码返回:

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 NAPTR queries).

错误从http抛出。由http.request ClientRequest类()。没有一个404不会产生这个错误。错误404意味着客户端能够与服务器通信,但是服务器无法找到所请求的内容。这个错误意味着域名系统找不到地址(dns)。js用于NAPTR查询)。