Node.js http.0请求urlhttp://freegeoip.net/json/14.12.111.113
您好,我正在尝试编写一个节点服务器代码,以从url检索经度和纬度信息。我总是收到此错误Node.js http.0请求urlhttp://freegeoip.net/json/14.12.111.113,node.js,http,Node.js,Http,您好,我正在尝试编写一个节点服务器代码,以从url检索经度和纬度信息。我总是收到此错误 Exception: Error: getaddrinfo ENOTFOUND Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16) 有人能帮忙吗 这是我正在使用的代码 var options = { ho
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”,路径以“/”开头
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();
不添加“http”,路径以“/”开头
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();
发布代码时请使用代码块格式…发布代码时请使用代码块格式。。。