Kam*_*n J 8 soap web-services node.js
我想通过Node.js中的SOAP客户端访问WSDL服务.我用肥皂节点模块.但我无法找到任何设置用户名和密码的文档.我不打算创建SOAP服务器,我只想要类似于PHP的SoapClient的SOAPClient,使用它我可以访问WSDL服务.
更新:
我已经分叉并定制了源代码以支持此功能https://github.com/sincerekamal/node-soap
ilo*_*loo 21
您可以提供如下的用户名和密码:
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) {
});
Run Code Online (Sandbox Code Playgroud)
(源自https://github.com/vpulim/node-soap/issues/56,谢谢你Gabriel Lucena https://github.com/glucena)
小智 7
添加基本身份验证的另一个选项是使用client.addHttpHeader.我尝试了setSecurity和设置wsdl_headers,但在对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);
});
Run Code Online (Sandbox Code Playgroud)
小智 6
只是为了分享我从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'));
});
Run Code Online (Sandbox Code Playgroud)
您需要通过将授权传递给 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();
}
});
Run Code Online (Sandbox Code Playgroud)
对现有答案的一个小调整:您也可以使用您的安全对象为 WSDL 请求创建标头,例如
const security = new soap.BasicAuthSecurity(username, password);
const wsdl_headers = {};
security.addHeaders(wsdl_headers);
soap.createClientAsync(url, { wsdl_headers }).then((err, client) => {
client.setSecurity(security);
// etc.
});
Run Code Online (Sandbox Code Playgroud)
或者,如果您使用比 BasicAuthSecurity 更复杂的东西,您可能还需要从安全对象中设置 wsdl_options,例如
const security = new soap.NTLMSecurity(username, password, domain, workstation);
const wsdl_headers = {}, wsdl_options = {};
security.addHeaders(wsdl_headers);
security.addOptions(wsdl_options);
soap.createClientAsync(url, { wsdl_headers, wsdl_options }).then((err, client) => {
client.setSecurity(security);
// etc.
});
Run Code Online (Sandbox Code Playgroud)