2017-01-27 19 views
-2

私は、指定されたウェブサイトのhtmlを返すAWS Lambdaで関数を作成しようとしています。それは私のコードです: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) 

答えて

1

あなたがhttp moduleのドキュメントを見れば、あなたが表示されます:

  • ホスト:要求を発行するサーバーのドメイン名またはIPアドレス
  • パス:要求パス。デフォルトは「/」です。もしあれば、クエリ文字列を含めるべきです。例えば。 '/index.html?page=12'