Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js http.0请求urlhttp://freegeoip.net/json/14.12.111.113_Node.js_Http - Fatal编程技术网

Node.js http.0请求urlhttp://freegeoip.net/json/14.12.111.113

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

您好,我正在尝试编写一个节点服务器代码,以从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 = {    
    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();

发布代码时请使用代码块格式…发布代码时请使用代码块格式。。。