【发布时间】:2015-05-18 23:13:29
【问题描述】:
我可以在浏览器中输入我的 url : 192.168.1.132 并得到“hello world”的正确响应,如果我执行 curl 192.168.1.132 也是如此
但是如果我运行这段代码
var http = require('http');
var options = {
host: 'http://192.168.1.132',
path: '/'
};
callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
我得到错误:
events.js:85
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND http://192.168.1.132
at errnoException (dns.js:44:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)
我做错了什么?
【问题讨论】:
-
主机不应包含协议;只是
192.168.1.132 -
没有协议,我得到类似的错误 events.js:85 throw er; // 未处理的 'error' 事件 ^ 错误:在 Socket.emit (events.js:107:17) 在 readableAddChunk (_stream_readable.js: 163:16) 在 Socket.Readable.push (_stream_readable.js:126:10) 在 TCP.onread (net.js:529:20)