使用https时Node.js中的套接字挂断错误

时间:2021-12-24 07:39:18

I'm trying to use HTTP GET method via Nodejs using secure connection https. Here is my code:

我正在尝试使用安全连接https通过Nodejs使用HTTP GET方法。这是我的代码:

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.

我无法使用HTTP,因为appspot需要https。请帮忙!提前致谢。

1 个解决方案

#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);
});

#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);
});