Khi sử dụng Node.js để thử và lấy nội dung html của trang web sau:
eternagame.wikia.com/wiki/EteRNA_Dictionary
Tôi nhận được lỗi sau đây:
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 đã tìm kiếm 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 tại sao lại như vậy, vì mã của tôi hoạt động hoàn hảo www.google.com
.
Đây là mã của tôi (thực tế được sao chép và dán từ một câu hỏi rất giống nhau, ngoại trừ máy chủ đã 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 mà tôi đã sao chép và dán từ: Cách thực hiện các cuộc gọi dịch vụ web trong Expressjs?
Tôi không sử dụng bất kỳ mô-đun nào với node.js.
Cảm ơn vì đã đọc.
var http = require("http");
hoặc var https = require("https");
dựa trên máy chủ từ xa
ENOTFOUND
nghĩa là gì