使用 axios 向 SOAP 端点发出请求

新手上路,请多包涵

我需要在我的 React 应用程序中使用 axios 向 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。

原文由 Peter 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
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)});

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

原文由 Anuragh KP 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进