【问题标题】:Receiving payload errors when trying to connect to REST API尝试连接到 REST API 时收到有效负载错误
【发布时间】:2016-06-08 23:37:16
【问题描述】:

我希望调用内部 REST API 并将有效负载传回 Mule 3.7.3。该请求只是 URL,没有正文,但我收到了诸如 nullPayload 之类的有效负载错误。

我怎样才能让它工作?

我正在使用这个公共 API https://apisandbox.openbankproject.com/obp/v2.0.0/banks 对其进行测试

我模拟的代码在这里:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.7.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <http:request-config name="HTTP_Request" host="https://apisandbox.openbankproject.com" port="443" basePath="/obp/v2.0.0" doc:name="HTTP Request Configuration"/>
    <flow name="account-balance-flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
        <set-payload value="#['{}']" doc:name="Set Payload"/>
        <http:request config-ref="HTTP_Request" path="/banks" method="GET" doc:name="HTTP"/>
        <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

【问题讨论】:

    标签: api rest mule


    【解决方案1】:

    主机不应包含 URL。它应该只是单独指定的主机和 HTTPS 协议。也无需为 GET 请求设置有效负载。更新的有效代码:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.7.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
    http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
    http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
         <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
        <http:request-config name="HTTP_Request" protocol="HTTPS" host="apisandbox.openbankproject.com" port="443" basePath="/obp/v2.0.0" doc:name="HTTP Request Configuration"/>
        <flow name="account-balance-flow">
            <http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="GET" doc:name="HTTP"/>
            <http:request config-ref="HTTP_Request" path="/banks" method="GET" doc:name="HTTP"/>
            <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
        </flow>
    </mule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      相关资源
      最近更新 更多