我使用IP地址获得ENOTFOUND Node.JS
我试图从外部网站获取信息,但我得到这个错误:
getaddrinfo ENOTFOUND
我的代码是:
var options = { host: 'http://DOMAIN_OR_IP_ADRESS/', port: 8080, path: 'PARAMS_GET (I GUESS)', method: 'GET', agent: false }; http.get(options, function(resp){ resp.on('data', function(chunk){ console.log(chunk); }); }).on("error", function(e){ console.log("Error: http://IP_OR_DOMAIN" + "\n" + e.message); console.log( e.stack ); });
当我使用这个选项:
var options = { hostname: 'www.google.com', port: 80, path: '/index.html', method: 'GET', agent: false };
它运作良好,但不是与我的域名或IP。
非常感谢。
我知道了!。
这是因为我把http://
放在域名或IP地址之前,
现在适用于:
var options = { host: 'DOMAIN_OR_IP_ADRESS', port: 8080, path: 'PARAMS_GET (I GUESS)', method: 'GET', agent: false };