javascript - Node-Soap 参数的 XML 字符串
问题描述
我正在尝试使用此处描述的方法发出肥皂请求:https ://www.npmjs.com/package/soap#example-with-xml-string-for-the-args 。
我想输入一个 xml 字符串而不是 JSON 对象,因为我无法在 JSON 中实现所需的语法。
const url = 'https://www.cashweb.nl/?api/3.0/wsdl';
const xmlStr = "<test></test>"
soap.createClient(url, function (err, client) {
if (err) {
response.status(500)
response.send("error creating client")
}
client.Import({ _xml: xmlStr }, function (err, result, rawResponse, soapHeader, rawRequest) {
// result is a javascript object
// rawResponse is the raw xml response string
// soapHeader is the response soap header as a javascript object
// rawRequest is the raw xml request string
if (err) {
response.status(500)
response.send(err + " " + rawRequest)
}
response.status(200)
response.send(rawRequest + " " + rawResponse)
})
});
虽然这给了我不需要的输出:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://www.cashweb.nl/?api/3.0" xmlns:ns="https://www.cashweb.nl/?api/3.0">
<soap:Body>
<tns:Import>
<_xml>
<test/>
</_xml>
</tns:Import>
</soap:Body>
</soap:Envelope>
如何摆脱 <_xml> 和标签。我是否错误地使用了该功能?
在 node-soap 测试中找到的示例https://github.com/vpulim/node-soap/blob/70c4f34b6370ffc59e7d4fe88d18d6312ff0bedc/test/client-test.js:
it('should allow passing in XML strings', function (done) {
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', _.assign({envelopeKey: 'soapenv'}, meta.options))
.then(function (client) {
assert.ok(client);
var xmlStr = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<title>404 - Not Found</title>\n\t</head>\n\t<body>\n\t\t<h1>404 - Not Found</h1>\n\t\t<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/beluga/pilot_rtm/beluga_beacon.js"></script>\n\t</body>\n</html>';
return client.MyOperationAsync({_xml: xmlStr});
})
.spread(function (result, raw, soapHeader) {})
.catch(function (err) {
done();
});
});
我正在尝试完成此操作,因为我的 Soap Api 需要以下方式的 CDATA 标记:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="https://www.cashweb.nl/?api">
<soapenv:Header/>
<soapenv:Body>
<api:Import>
<relatie>202943</relatie>
<email>helpdesk@cash.nl</email>
<pass>*********</pass>
<importData>
<![CDATA[<?xml version="1.0">
<CASH>
<R0301>
<F201>4360</F201>
<F302>161201</F302>
<F306>kantoorbenodigdheden</F306>
<F307>10000</F307>
<F901>KAS</F901>
</R0301>
</CASH>]]>
</importData>
<administration>
<api:admCode>demo</api:admCode>
<api:admMap/>
</administration>
<formaat>0</formaat>
</api:Import>
</soapenv:Body>
</soapenv:Envelope>
解决方案
最后,我这样修复它:
function scheduleCash(servicebonnummer, bondatum, servicestatus, tijdstip) {
const url = "https://www.cashweb.nl/?api/3.0/wsdl";
const xml = {
relatie: "",
email: "",
pass: "",
importData: `<![CDATA[<CASH><R3600><F3600>${servicebonnummer}</F3600><F4102>${servicestatus}</F4102><F3601>${bondatum.format(
"YYMMDD"
)}</F3601></R3600></CASH>]]>`,
administration: { admCode: "" },
formaat: 0
};
return soap.createClientAsync(url).then(client => {
return client.ImportAsync(xml);
});
}
推荐阅读
- wix - wix - 错误 CNDL0004:从命令行运行时文件元素包含意外的属性“src”
- python - Gensim 自训练嵌入负载
- cryptography - 如何使用 Google Tink 创建对称加密密钥?
- javascript - 当我们从 DOM 中追加/删除元素时的 DOM 行为
- javascript - 使用函数阻止了我的代码工作?
- ruby-on-rails - 使用 MiniTest,在尝试测试“omniauth-google-oauth2”gem 时,我不断收到 302 重定向到我的登录路径
- arrays - 订阅 Angular 6
- ssis - 如何在 SSIS 的 Box.com 文件夹中搜索新文件以检测新文件并处理此文件中的数据?
- turbo-c - 以未定义方式表现的双重数据类型
- javascript - 如何在 SlickGrid 中对服务器端的数据进行分组