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

项目为了安全把原来http请求方式都改成了https请求方式,我就临时接到一个任务,把原先使用Node.js编写的程序改造成https请求。

处理过程中就遇到了如下错误:

headers: {}
    at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
    at TLSSocket.emit (events.js:210:5)
    at TLSSocket._finishInit (_tls_wrap.js:794:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12)
code: "UNABLE_TO_VERIFY_LEAF_SIGNATURE"

错误信息提示的很清楚是:无法验证请求接口签名

解决办法: rejectUnauthorized参数设置成false

var https = require('https');

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

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);
});
原文地址:https://www.cnblogs.com/reggieqiao/p/13253907.html