【问题标题】:React.js: Is it possible to call a SOAP web service using axios?React.js:是否可以使用 axios 调用 SOAP Web 服务?
【发布时间】: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

【问题讨论】:

标签: reactjs soap axios


【解决方案1】:

是的,在 axios 中是可能的。

在此处查看您有大量工作示例的地方 -> Make request to SOAP endpoint using axios

如果您难以获得响应,请检查您尝试调用的 API 的服务器日志。

【讨论】:

    猜你喜欢
    • 2016-06-12
    • 2011-11-26
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多