Khi sử dụng Node.js để thử và nhận nội dung html của trang web sau đây:Node.js getaddrinfo ENOTFOUND
eternagame.wikia.com/wiki/EteRNA_Dictionary
tôi nhận được lỗi sau:
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
tôi đã làm đã tra cứu lỗi này trên stackoverflow và nhận ra rằng điều này là do node.js không thể tìm thấy máy chủ từ DNS (tôi nghĩ). Tuy nhiên, tôi không chắc chắn tại sao điều này lại xảy ra, vì mã của tôi hoạt động hoàn hảo trên www.google.com
.
Đây là mã của tôi (thực tế sao chép và dán từ một câu hỏi rất tương tự, trừ trường hợp chủ nhà thay đổi):
var http = require("http");
var options = {
host: 'eternagame.wikia.com/wiki/EteRNA_Dictionary'
};
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);
});
});
Đây là nguồn gốc nơi tôi sao chép và dán từ: How to make web service calls in Expressjs?
tôi không sử dụng bất kỳ mô-đun nào có node.js.
Cảm ơn bạn đã đọc,
Vineet
http://stackoverflow.com/a/11921896/2106820 –