2017-08-31 87 views
0

我需要在我的React應用程序中使用axios向SOAP端點發出請求。因此,我需要在請求中傳遞xml數據並接收xml數據作爲響應。使用axios向SOAP端點發出請求

我已經使用jios數據的axios後,但我如何使用相同的XML? PFB我使用相同的代碼,但它不起作用。

JSON POST請求:

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請分享。

+0

你試試這個:'頭:{ '內容類型': '應用程序/ XML'}' – DrunkDevKek

+0

@DrunkDevKek:是的,我真的做到了,不行! –

+0

您是否收到任何錯誤?也許你可以擴展你的意思,它不起作用。 –

回答

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

此代碼的幫助,使SOAP請求