http.request的url http://freegeoip.net/json/14.12.111.113

嗨,我想写一个节点服务器代码来检索经纬度信息从http://freegeoip.net/json/14.12.111.113 ia总是得到这个错误。

Exception: Error: getaddrinfo ENOTFOUND Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16) 

有人可以帮忙吗?

这里是我使用的代码..

 var options = { host: 'http://freegeoip.net/', path: 'json/14.12.111.113', method: 'GET' }; var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); // write data to request body req.write('data\n'); req.write('data\n'); req.end(); 

不要添加'http',path以'/'开始

 var options = { host: 'freegeoip.net', path: '/json/14.12.111.113', method: 'GET' }; var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); // write data to request body req.write('data\n'); req.write('data\n'); req.end();