Node.js使用https请求时,出现“SSL23_GET_SERVER_HELLO”错误

Node.js程序改造成https请求,遇到了另外一个问题

错误提示如下:

SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/s23_clnt.c:772

经过排查错误发现是:Node.js版本太旧默认使用TLS1.1协议请求,解决这个问题有两种方法:

1.手动指定成TLS1.2协议,secureProtocol参数设置成TLSv1_2_method

var https = require('https');

var options = {
  hostname: 'www.yourwebiste.com',
  port: 443,
  method: 'GET',
  path: '/validate',
  secureProtocol: 'TLSv1_2_method',
};

var req = https.request(options, function (res) {
  res.on('data', function (d) {
    process.stdout.write(d);
  });
});
req.end();

req.on('error', function (e) {
  console.error(e);
});

2.升级Node.js到最新的稳定版本

原文地址:https://www.cnblogs.com/reggieqiao/p/13254788.html