下面是调用http get请求时出现的错误
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 我的代码抛出错误
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();
有什么想法,为什么会出现这个错误?
最佳答案
ENOENT
是一个错误,表示名称解析未返回任何结果。您将主机名指定为 http://xyz.com
,但主机名中不允许使用冒号。你想要:
var options = {
host: 'xyz.com',
关于node.js - 在node.js中使用http时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14232361/