我在使用axios 时调用REST API时取得了成功
但是,我需要从旧系统调用SOAP web服务
这可能使用axios吗?
请参阅我失败尝试的示例代码:
callSoap() {
let xmls =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<mtdGetTestNumber xmlns="http://test.com/services">
<AccountNumber>string</AccountNumber>
<RequestType>string</RequestType>
</mtdGetTestNumber>
</soap:Body>
</soap:Envelope>';
let xmls2 =
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<mtdGetTestNumber xmlns="http://test.com/services">
<AccountNumber>string</AccountNumber>
<RequestType>string</RequestType>
</mtdGetTestNumber>
</soap12:Body>
</soap12:Envelope>';
return axios.post(
"http://192.254.1.2:8083/Service.asmx?op=mtdTestNumber",
xmls,
{
headers: { "Content-Type": "text/xml" },
}
);
}
当我返回错误响应时,这不会显示任何错误。
如果可能的话,有人能启发我吗?
或者我应该在后台创建一个API(在我的例子中是它的Spring Boot(来调用SOAP API,然后将xml响应从SOAP转换为JSON,并使用该JSON响应web?
TIA-
是的,这在axios中是可能的。
请参阅此处,其中有大量的工作示例->使用axios 向SOAP端点发出请求
如果您很难得到响应,请检查您试图调用的API的服务器日志。