Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Node.js SOAP客户端中设置授权_Node.js_Web Services_Soap - Fatal编程技术网

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

在Node.js SOAP客户端中设置授权,node.js,web-services,soap,Node.js,Web Services,Soap,我想通过Node.js中的SOAP客户端访问WSDL服务。我使用了soap节点模块。但是我找不到任何文档来设置用户名和密码。我不打算创建SOAP服务器,我只想要SOAPClient,它类似于PHP的SOAPClient,我应该能够使用它访问WSDL服务 更新: 我对源代码进行了分叉和定制,以支持此功能您可以提供如下用户名和密码: var soap = require('soap'); var url = 'your WSDL url'; var auth = "Basic " + new Buf

我想通过Node.js中的SOAP客户端访问WSDL服务。我使用了soap节点模块。但是我找不到任何文档来设置用户名和密码。我不打算创建SOAP服务器,我只想要SOAPClient,它类似于PHP的SOAPClient,我应该能够使用它访问WSDL服务

更新


我对源代码进行了分叉和定制,以支持此功能

您可以提供如下用户名和密码:

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

(来源于,谢谢Gabriel Lucena)

我想分享一下我读到的:


添加基本身份验证的另一个选项是使用client.addHttpHeader。我尝试了设置安全性和设置wsdl_头,但在向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();
    }
});

对现有答案的一个小调整:您也可以使用您的安全对象为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.
});
或者,如果您使用的是比BasicAuthSecurity更复杂的东西,您可能还需要从安全对象设置wsdl_选项,例如

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

如果wsdl也支持身份验证,那么这个错误不会发生吗?根据我的经验,不会。身份验证似乎是在获取wsdl之前完成的。不会,wsdl用于构建传递给回调的客户机,然后在回调上设置安全性。据我所知,当wsdl不需要身份验证、需要不同的身份验证或从文件系统加载时,该方法是存在的。我认为您需要将auth传递给createclient方法:var auth=“Basic”+newbuffer('username'+':'+'password');var client=Soap.createClient('wsdlUrl',{wsdl_头:{Authorization:auth}},(err,client)=>{if(err){throw err;}else{client.yourMethod();});我发现wsdl_选项对我不起作用,但与您类似,addHttpHeader也起到了作用。如何设置securityMode None?
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.
});