1

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.

5
  • "socket hang up" means the server you're contacting never sent a response ? Commented Apr 7, 2014 at 12:53
  • Is there any error log by req.on('error' .... console.log(e);? Commented Apr 7, 2014 at 13:14
  • @adeneo but when i post this url "https://birra-io2014.appspot.com/_ah/api/birra/v1/beer" i get all my content. I did this using curl as well and it worked, why is it not working with node.js. Commented Apr 7, 2014 at 13:27
  • 1
    @AmolMKulkarni - well i posted the error, either you do console.log or console.error, it gives the same thing. Commented Apr 7, 2014 at 13:29
  • @user3275261 Well, I checked and changed code of yours and its working for, I have put same code in my answer. Please let me know if it didn't work for you too. I have changed port, host & path Commented Apr 7, 2014 at 13:41

1 Answer 1

2

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);
});
Sign up to request clarification or add additional context in comments.

2 Comments

it gives: ERROR object ==>Error: connect ETIMEDOUT
I think you are behind a proxy server. since you mentioned host: 'my_proxy_address'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.