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 ?

0

2 Answers 2

3

ENOENT is an error that indications name resolution did not return any results. You specify the hostname as http://xyz.com, but colons are not allowed in hostnames. You want:

var options = {
    host: 'xyz.com',
Sign up to request clarification or add additional context in comments.

Comments

2

You specify the host as http://xyz.com, which should just be xyz.com.

This value is used to resolve the IP address of the host you're trying to connect to using DNS.

1 Comment

Thanks for the answers, Now I am getting a different error events.js:66 throw arguments[1]; // Unhandled 'error' event ^ Error: socket hang up at createHangUpError (http.js:1263:15) at Socket.socketCloseListener (http.js:1314:23) at Socket.EventEmitter.emit (events.js:115:20) at Socket._destroy.destroyed (net.js:356:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.