【发布时间】:2014-11-29 16:08:02
【问题描述】:
我希望通过node 连接到新闻提要网址列表,并通过socket.io 获取实时数据。为此,我尝试在server.js 中使用单个网址,如下所示:
var http = require("http");
var options = {
host: 'http://economictimes.feedsportal.com/c/33041/f/534037/'
};
http.get(options, function (http_res) {
// initialize the container for our data
var data = "";
// this event fires many times, each time collecting another piece of the response
http_res.on("data", function (chunk) {
// append this chunk to our growing `data` var
data += chunk;
});
// this event fires *one* time, after all the `data` events/chunks have been gathered
http_res.on("end", function () {
// you can use res.send instead of console.log to output via express
console.log(data);
});
});
当我执行node server.js 时,它会抛出一个错误
"Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)"
有什么方法可以从数组中传递每个新闻提要 url 以通过node 连接它并通过socket.io 获取最新消息???
【问题讨论】: