我正在尝试在AWS Lambda中创建函数,该函数返回给定网站的html。那是我的代码:
console.log('Loading function');
exports.handler = (event, context, callback) => {
var util = require("util"),
http = require("http");
var options = {
host: "www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html",
port: 80,
path: "/"
};
var content = "";
var req = http.request(options, function(res) {
res.setEncoding("utf8");
res.on("data", function (chunk) {
content += chunk;
});
res.on("end", function () {
util.log(content);
callback(null, content);
});
});
req.end();
};
它非常适合'www.google.com'作为选项中的主机参数,但是当我尝试更复杂时,类似于代码中的给定参数,我收到一个错误:
Error: getaddrinfo ENOTFOUND www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html:80
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
答案 0 :(得分:1)
如果查看http module的文档,您会看到: