how to set headers using node-soap in node.js
Solution 1
It may not be useful now however inorder to answering this question which is still open, here it goes.
You can make use of the method Client.addSoapHeader. As per the documentation
Client.addSoapHeader(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node
Options
soapHeader Object({rootName: {name: "value"}}) or strict xml-string Optional parameters when first arg is object :
name Unknown parameter (it could just a empty string)
namespace prefix of xml namespace
xmlns URI
So you need to create an object and pass that to this method like:
var soapHeader = {
"Username": "foo",
"Password" : "bar"
};
client.addSoapHeader(soapHeader);
Solution 2
According with the documentation , for aggregate HTTP Headers, you can put headers, example code:
soap.createClient(url,
function (err, client) {
if(err){
console.log(err);
} else{
console.log(client.describe())
var soapHeaders = {
'Channel':'PB',
'RqUID':'1987'
}
client.addHttpHeader('<nameH1>', 'valueH1');
client.addHttpHeader('<nameH2>', 'valueH2');
//then, continue calling the soap operation
}
Vartan Arabyan
Updated on July 16, 2022Comments
-
Vartan Arabyan almost 2 years
I am trying to consume a wsdl service and found node-soap, but I cannot find how to set some headers.
Example :
header = { "Username": "foo", "Password" : "bar" }
The reason I need this is because the wsdl I am trying to consume requires the username and password via the headers.
Thanks in advance