gpt4 book ai didi

javascript - 如何使用 node-soap 创建自定义请求

转载 作者:行者123 更新时间:2023-12-01 03:11:02 25 4
gpt4 key购买 nike

这是我需要发送到 wsdl 的消息:

<?xml version="1.0" encoding="UTF-8" ?>    
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>

我有这个代码:

const wsdlOptions = {
envelopeKey: "soapenv"
};
soap.createClient(URL, wsdlOptions, function(err, client) {
const args = {
_xml: '<tem:ConsultarCreditos><tem:usuario> DEMO010233001 </tem:usuario><tem:password>Pruebas1a$</tem:password></tem:ConsultarCreditos>',
}
client.ConsultarCreditos(args, function(err, result, raw, soapHeader) {
console.log('last request: ', client.lastRequest)
});

});

结果如下:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:tns="http://tempuri.org/"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract">
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>

我需要更改标签 soapenv:Envelope 的属性,但我不知道该怎么做。

我只需要这些属性:

> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
> xmlns:tem="http://tempuri.org/"

任何帮助将不胜感激

最佳答案

也许这不是最好的解决方案,但它对我有用。在回调 createCliete 中,重写属性 client.wsdl.xmlnsInEnvelope 和我想要的 xmlns,client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';

完整代码:

    soap.createClient(URL, wsdlOptions, function(err, client) {
client.wsdl.xmlnsInEnvelope = 'xmlns:tem="http://tempuri.org/"';
const args = {
_xml: '<tem:ConsultarCreditos><tem:usuario> DEMO010233001 </tem:usuario><tem:password>Pruebas1a$</tem:password></tem:ConsultarCreditos>',
}
client.ConsultarCreditos(args, function(err, result, raw, soapHeader) {
console.log('last request: ', client.lastRequest)
});

});

结果:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tem="http://tempuri.org/">
<soapenv:Body>
<tem:ConsultarCreditos>
<tem:usuario>DEMO010233001</tem:usuario>
<tem:password>Pruebas1a$</tem:password>
</tem:ConsultarCreditos>
</soapenv:Body>
</soapenv:Envelope>

关于javascript - 如何使用 node-soap 创建自定义请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45853357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com