Reputation: 27544
I got the error socket hang up
when running the following script. But if I changed the host from www.google.com
to www.nodejs.org
, everything was working fine. Why?
var http = require('http');
var options = {
host: 'www.google.com',
port: 443,
path: '/'
};
http.get(options, function(data) {
console.log('OK');
data.resume();
}).on('error', function(e) {
console.log('Error: ' + e.message);
});
Upvotes: 0
Views: 662
Reputation: 203231
www.google.com
completely rejects non-HTTPS requests sent to its HTTPS server, and www.nodejs.org
will not (it will, however, return a HTTP 400 status because you are making a plain HTTP request to a HTTPS server).
To make HTTPS requests, you need to use the https
module:
var http = require('https');
Upvotes: 2