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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31032520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:05:43  来源:igfitidea点击:

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

javascriptnode.jssslsoap-client

提问by Sarfaraz Khan

I have created a soap client in node.js using soap.js.Soap communication is done over https. When I try to connect I keep getting this error

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

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

{ [错误:自签名证书] 代码:'DEPTH_ZERO_SELF_SIGNED_CERT' }

Below is my code

下面是我的代码

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

  });

I've also tried the following ssl setting but did't work out

我也尝试了以下 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
};

Any help would be appreciated !!

任何帮助,将不胜感激 !!

回答by Sarfaraz Khan

Found it yesterday on their github repo

昨天在他们的 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.

@tesfel tesfel 于 2 月 17 日发表评论

将证书添加到您计算机上的受信任列表或添加

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

到您的代码。