Reputation: 85
I'm trying to use HTTP GET method via Nodejs using secure connection https. Here is my code:
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';
var options = {
host: 'my_proxy_address',
port: 3128,
path: 'https://birra-io2014.appspot.com/_ah/api/birra/v1/beer',
method: 'GET',
headers: {
accept: '*/*'
}
};
var req = https.request(options, function(res) {
console.log(res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
When i run this, i get an error:
{ [Error: socket hang up] code: 'ECONNRESET', sslError: undefined }
I cannot use HTTP because appspot requires https. Please help! Thanks in advance.
Upvotes: 1
Views: 3129
Reputation: 21629
Try the following code. (Its working for me)
var https = require('https');
var options = {
port: 443,
host: 'birra-io2014.appspot.com',
path: '/_ah/api/birra/v1/beer',
method: 'GET',
headers: {
accept: '*/*'
}
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error('ERROR object ==>' + e);
});
Upvotes: 2