使用 axios 向 SOAP 端点发出请求 [英] Make request to SOAP endpoint using axios
本文介绍了使用 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)});
此代码有助于发出soap请求
这篇关于使用 axios 向 SOAP 端点发出请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文