如何忽略自签名证书错误 node.js soap.js

how to ignore self signed certificate error node.js soap.js

我使用 soap.js 在 node.js 中创建了一个 soap 客户端。Soap 通信是通过 https 完成的。当我尝试连接时,我不断收到此错误

{ [Error: self signed certificate] code: 'DEPTH_ZERO_SELF_SIGNED_CERT' }

下面是我的代码

var url = '../public/test.wsdl';

var client = soap.createClient(url,sslOptions, function(err, client) {
    client.setSecurity(new soap.WSSecurity('testuser', 'testpassword'));
      client.CheckStatus(args, function(err, result) {
          console.log(err);
        //  console.log(result);
      });

  });

我也尝试了以下 ssl 设置,但没有成功

sslOptions = {
  key: fs.readFileSync( '../certs/test-key.pem'),
  cert: fs.readFileSync( '../certs/test-cert.pem'),
  rejectUnauthorized : false,
  secureOptions : constants.SSL_OP_NO_TLSv1_2,
  strictSSL : false
};

如有任何帮助,我们将不胜感激!!

昨天在他们的 github repo

上找到的

@tesfel tesfel commented on 17 Feb

Add the cert to your trusted list at you computer or add

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

to your code.