我的soap-node有问题,我的标题有auth:
XML-service SOAP
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Autentication xmlns="http://tempuri.org/">
<Pass>string</Pass>
<Us>string</Us>
</Autentication>
</soap:Header>
<soap:Body>
<getdata xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
App.js - Node.js
var soap = require('soap');
var url = "http://localhost/abc/example.asmx?WSDL"
var Autentication = {
"Autentication": {
"Pass" : "david",
"Us" : "hackro"
}
}
var args = {}
soap.createClient(url, function(err, client) {
if(err)return console.log(err)
client.addSoapHeader(Autenticacion)
client.ObtieneKey(args, function(err, result,body) {
if(err) return console.log(body)
console.log(result);
console.log(body);
})
})
但我的身份验证失败,因为返回空
{ data: "" }
我看到这个answer但它不起作用。
答案 0 :(得分:0)
我解决了以这种方式发送标题的问题
var Autentication ='<Autentication xmlns="http://tempuri.org/">Pass>david</Pass><Us>hackro</Us>/Autentication></soap:Header>'
添加标题
client.addSoapHeader(Autentication)
祝你好运