小编典典

使用axios向SOAP端点发出请求

reactjs

我需要axiosReact应用程序中使用SOAP端点进行请求。因此,我需要在请求中传递xml数据,并在响应中接收xml数据。

我已将axios帖子与json数据一起使用,但如何将其用于xml?PFB我正在使用相同的代码,但是它不起作用。

JSON发布请求:

var xmlData = <note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

var config = {
  headers: {'Content-Type': 'text/xml'}
};

axios.post('/save', xmlData, config);

TIA,如果您有任何经验,请分享。


阅读 812

收藏
2020-07-22

共1个答案

小编典典

let xmls='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"\
                            xmlns:web="http://www.webserviceX.NET/">\
            <soapenv:Header/>\
            <soapenv:Body>\
              <web:ConversionRate>\
                <web:FromCurrency>INR</web:FromCurrency>\
                <web:ToCurrency>USD</web:ToCurrency>\
              </web:ConversionRate>\
            </soapenv:Body>\
          </soapenv:Envelope>';

axios.post('http://www.webservicex.com/CurrencyConvertor.asmx?wsdl',
           xmls,
           {headers:
             {'Content-Type': 'text/xml'}
           }).then(res=>{
             console.log(res);
           }).catch(err=>{console.log(err)});

此代码有助于提出肥皂请求

2020-07-22