Ответ 1
Я решил свою проблему.
По-видимому, если вы решите подать URL-адрес в качестве первого параметра в .get()
, вы должны включить http://
вверху URL-адреса, например, http://www.google.com
.
var http = require('http');
exports.handler = function (event, context) {
http.get('http://www.google.com', function (result) {
console.log('Success, with: ' + result.statusCode);
context.done(null);
}).on('error', function (err) {
console.log('Error, with: ' + err.message);
context.done("Failed");
});
};
В качестве альтернативы вы можете указать первый параметр как хеш опций, где hostname
может быть простой формой URL-адреса. Пример:
var http = require('http');
exports.handler = function (event, context) {
var getConfig = {
hostname: 'www.google.com'
};
http.get(getConfig, function (result) {
console.log('Success, with: ' + result.statusCode);
context.done(null);
}).on('error', function (err) {
console.log('Error, with: ' + err.message);
context.done("Failed");
});
};