1

Below is the error getting while calling http get request

events.js:66
throw arguments[1]; // Unhandled 'error' event
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer [as oncomplete] (dns.js:123:16)

PFB my code throwing the error

var options = {
host: 'http://xyz.com',
port: 80,
path : 'test?query=' + escape(req.params.searchTerm) + '&offset=0&hits=500',
method: 'GET',
headers: {
Cookie : "session=" + session
}
};

console.log("Start");
var x = http.request(options,function(subRes){
console.log("Connected");
subRes.on('data',function(data){
console.log("===================data===" +util.inspect(data));
});
});

x.end();

Any ideas, why this error ?

4

2 回答 2

3

ENOENT是指示名称解析未返回任何结果的错误。您将主机名指定为http://xyz.com,但主机名中不允许使用冒号。你要:

var options = {
    host: 'xyz.com',
于 2013-01-09T09:55:53.717 回答
2

您将主机指定为http://xyz.com,它应该只是xyz.com

此值用于解析您尝试使用 DNS 连接的主机的 IP 地址。

于 2013-01-09T09:53:46.220 回答