在Node.js SOAP客户端中设置授权

我想通过Node.js中的SOAP客户端访问WSDL服务。 我用肥皂节点模块。 但我无法find任何文件来设置用户名和密码。 我不打算创buildSOAP服务器,我只是希望SOAPClient类似于PHP的SoapClient,使用它我应该能够访问WSDL服务。

更新

我已经分叉和定制源支持这个functionhttps://github.com/sincerekamal/node-soap

Solutions Collecting From Web of "在Node.js SOAP客户端中设置授权"

你可以像这样提供用户名和密码:

var soap = require('soap'); var url = 'your WSDL url'; var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64"); soap.createClient(url, { wsdl_headers: {Authorization: auth} }, function(err, client) { }); 

(来自https://github.com/vpulim/node-soap/issues/56 ,谢谢你Gabriel Lucena https://github.com/glucena

只是分享我从https://github.com/vpulim/node-soap读到的内容:

 var soap = require('soap'); var url = 'your WSDL url'; soap.createClient(url, function(err, client) { client.setSecurity(new soap.BasicAuthSecurity('your username','your password')); }); 

另一个添加基本身份validation的选项是使用client.addHttpHeader。 我尝试了setSecurity和设置wsdl_headers,但是在authentication到Cisco CUCM AXL时都不适用于我。

这是什么对我有用:

 var soap = require('soap'); var url = 'AXLAPI.wsdl'; // Download this file and xsd files from cucm admin page var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64"); soap.createClient(url,function(err,client){ client.addHttpHeader('Authorization',auth); }); 

你需要通过授权给wsdl_headers对象来设置用户名和密码

 var auth = "Basic " + new Buffer('username' + ':' + 'password').toString("base64"); var client = Soap.createClient('wsdlUrl', { wsdl_headers: { Authorization: auth } }, (err, client) => { if (err) { throw err; } else { client.yourMethod(); } });