[英]How to send a SOAP request in javascript, like in SoapUI
我目前正在开发一个 NodeJS 项目,我需要在其中使用一些 soap/xml/wsdl。 问题是无法弄清楚这些是如何工作的,所以请原谅我的无知。 这是我需要的:
我有这个 WSDL 站点,我需要从中获得一些答案。 我已经想出了如何在 SoapUI 中做到这一点,但我不知道如何在 Javascript 中做到这一点。 我在 soapUI 中发送的请求如下所示:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:uni="https://uni-login.dk">
<soap:Header/>
<soap:Body>
<uni:hentDataAftaler>
<uni:wsBrugerid>?</uni:wsBrugerid>
<uni:wsPassword>?</uni:wsPassword>
</uni:hentDataAftaler>
</soap:Body>
</soap:Envelope>
我也有 wsdl 链接: https : //wsiautor.uni-login.dk/wsiautor-v4/ws?WSDL
我还尝试在 nodeJS(SOAP、Strong-SOAP 和 Easy-SOAP)中使用一些 npm-packages,但我也无法使这些工作。
我希望你有一些建议,如果你需要更多信息来回答我的问题,请告诉我:)
您可以使用easy-soap-request
,这篇文章https://medium.com/@caleblemoine/how-to-perform-soap-requests-with-node-js-4a9627070eb6可能会有所帮助。 它只是 axios 的一个薄包装。
我的问题代码:
const soapRequest = require('easy-soap-request');
const url = 'https://wsiautor.uni-login.dk/wsiautor-v4/ws';
const headers = {
'Content-Type': 'application/soap+xml;charset=UTF-8',
'soapAction': 'https://wsiautor.uni-login.dk/hentDataAftaler',
};
// example data
const xml = `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:uni="https://uni-login.dk">
<soap:Header/>
<soap:Body>
<uni:hentDataAftaler>
<uni:wsBrugerid>?</uni:wsBrugerid>
<uni:wsPassword>?</uni:wsPassword>
</uni:hentDataAftaler>
</soap:Body>
</soap:Envelope>
`;
// usage of module
soapRequest(url, headers, xml).then(({response: {body, statusCode}}) => {
console.log(body);
console.log(statusCode);
}).catch((errorBody) => {
console.error(errorBody);
});
将来可能对某人有用:将此(url, headers, xml)
更改为( {url, headers, xml})
对于那些在@aristoll 回答后遇到错误的人。 试试这个,它会工作
前
soapRequest(url, headers, xml).....
后
soapRequest({url, headers, xml})......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.