javascript - 如何在 javascript 中发送 SOAP 请求,例如在 SoapUI 中
问题描述
我目前正在开发一个需要使用soap/xml/wsdl 的NodeJS 项目。问题是无法弄清楚这些是如何工作的,所以请原谅我的无知。这是我需要的:
我有这个 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 中使用一些 npm 包(SOAP、Strong-SOAP 和 Easy-SOAP),但我也无法使这些工作。
我希望你有一些建议,如果你需要更多信息来回答我的问题,请告诉我:)
解决方案
您可以使用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);
});
推荐阅读
- reactjs - 递归地将选择器传递给动态创建的子节点以查找 Redux 存储数据
- r - 如何在R中的图中添加一条线
- mysql - 从另一个窗口更新 WPF 窗口(不是 MainWindow)中的数据网格。*不使用 MVVM*
- ruby - GoogleSheetAPIv4 rubysdk 按编号访问列
- java - 在 Firebase 中过滤快照结果
- snowflake-cloud-data-platform - 更改雪花数据库所有者
- typescript - 键入单个记录条目
- c# - ASP.NET 可以在视图中修改 ViewModel 吗?
- java - 如何验证仅包含 PDF 内容的网站 URL?
- javascript - 不断收到“UnhandledPromiseRejectionWarning”让我退出 node.js