带有 Node 和 strong-soap 的 Soap 客户端返回带有证书的错误
Soap client with Node and strong-soap returning error with cerficate
我正在使用 strong-soap(但与 node-soap 的结果相同)节点模块来连接 soap 服务。
在第一步中,我正在创建客户端并尝试连接一个方法,在本例中为 "doLogin" 方法。
我的代码是:
soap.createClient(url, clientOptions, (err, client) => {
var loginApi = { UserName: "xxxx", Password: "xxxxxx" };
var loginUser = {
userName: "comercial@xxxxx.com"
};
client.addSoapHeader(header);
//client.setSecurity(new soap.BasicAuthSecurity(loginApi));
// we now have a soapClient - we also need to make sure there's no `err` here.
client.doLogin(loginUser, (err, result) => {
//'result' is the response body
console.error(err);
console.log("Result: \n" + JSON.stringify(result));
});
但是变量 err 在控制台中返回了这个错误:
{ Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code:
'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
结果是 undefined
.
- 为什么会出现这个错误?
- 错误未定义结果?
我遇到了同样的错误,无法验证第一个证书。
这是因为 SSL 证书未验证。
您的 nodejs 脚本调用您的服务器,它将执行完整的 TLS 检查过程(如您所愿)。这将检查证书的有效性等。
要解决此问题,您可以运行执行以下步骤:
npm config set strict-ssl false
作为最佳实践,明智的做法是将其设置回 true 后记,这样您就不会意外安装您实际上不信任的不受信任模块。
在此之后,
npm cache clean --force
添加以下环境变量:
NODE_TLS_REJECT_UNAUTHORIZED=0
对于Linux:
export NODE_TLS_REJECT_UNAUTHORIZED=0
对于 Nginx
NODE_TLS_REJECT_UNAUTHORIZED=0
对于Window:
这将仅针对当前命令提示符屏幕设置,
set NODE_TLS_REJECT_UNAUTHORIZED=0
这已经解决了我的问题。请尝试
注意:请确保您不要在生产中保留此选项。请不要禁用 TLS 检查。
已修复:
我添加了正确的证书和 rejectUnauthorized: false
来创建客户端,并向 headers 添加了 "envelope" 指令,现在可以正常工作了。
我不喜欢安全主题的指令 rejectUnauthorized: false
,我想知道如何在生产环境中删除它。
谢谢!!
我正在使用 strong-soap(但与 node-soap 的结果相同)节点模块来连接 soap 服务。
在第一步中,我正在创建客户端并尝试连接一个方法,在本例中为 "doLogin" 方法。
我的代码是:
soap.createClient(url, clientOptions, (err, client) => {
var loginApi = { UserName: "xxxx", Password: "xxxxxx" };
var loginUser = {
userName: "comercial@xxxxx.com"
};
client.addSoapHeader(header);
//client.setSecurity(new soap.BasicAuthSecurity(loginApi));
// we now have a soapClient - we also need to make sure there's no `err` here.
client.doLogin(loginUser, (err, result) => {
//'result' is the response body
console.error(err);
console.log("Result: \n" + JSON.stringify(result));
});
但是变量 err 在控制台中返回了这个错误:
{ Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:639:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code:
'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
结果是 undefined
.
- 为什么会出现这个错误?
- 错误未定义结果?
我遇到了同样的错误,无法验证第一个证书。 这是因为 SSL 证书未验证。
您的 nodejs 脚本调用您的服务器,它将执行完整的 TLS 检查过程(如您所愿)。这将检查证书的有效性等。
要解决此问题,您可以运行执行以下步骤:
npm config set strict-ssl false
作为最佳实践,明智的做法是将其设置回 true 后记,这样您就不会意外安装您实际上不信任的不受信任模块。
在此之后,
npm cache clean --force
添加以下环境变量:
NODE_TLS_REJECT_UNAUTHORIZED=0
对于Linux:
export NODE_TLS_REJECT_UNAUTHORIZED=0
对于 Nginx
NODE_TLS_REJECT_UNAUTHORIZED=0
对于Window: 这将仅针对当前命令提示符屏幕设置,
set NODE_TLS_REJECT_UNAUTHORIZED=0
这已经解决了我的问题。请尝试
注意:请确保您不要在生产中保留此选项。请不要禁用 TLS 检查。
已修复:
我添加了正确的证书和 rejectUnauthorized: false
来创建客户端,并向 headers 添加了 "envelope" 指令,现在可以正常工作了。
我不喜欢安全主题的指令 rejectUnauthorized: false
,我想知道如何在生产环境中删除它。
谢谢!!