【发布时间】:2020-11-12 01:14:12
【问题描述】:
我在使用 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
【问题讨论】:
-
这能回答你的问题吗? Make request to SOAP endpoint using axios
-
不,没有帮助