使用axios向SOAP端点发出请求 [英] Make request to SOAP endpoint using axios

查看:1058
本文介绍了使用axios向SOAP端点发出请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的React应用程序中使用axios向SOAP端点发出请求.因此,我需要在请求中传递xml数据,并在响应中接收xml数据.

I need to make request to SOAP endpoint using axios in my React application. Hence I need to pass xml data in request and receive xml data in response.

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

I have used the axios post with json data but how do I use the same for xml? PFB the code I am using for the same, but it does not work.

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,如果您有任何经验,请分享.

Please share if you have any experience with this, TIA.

推荐答案

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)});

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

这篇关于使用axios向SOAP端点发出请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆