How to send a SOAP request in javascript, like in SoapUI

前端 未结 1 1858
后悔当初
后悔当初 2021-01-20 14:33

I am currently working on a NodeJS project where I need to use some soap/xml/wsdl. The problem is that can\'t figure out how any of these works, so forgive my ignorance. Her

相关标签:
1条回答
  • 2021-01-20 15:23

    You can use easy-soap-request,and this article https://medium.com/@caleblemoine/how-to-perform-soap-requests-with-node-js-4a9627070eb6 may help. It is just a thin wrapper of axios.

    My code for your question:

    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);
    });
    
    0 讨论(0)
提交回复
热议问题