如何在消耗剩余 api 的同时发送 json 有效载荷

How to send a json payload while consuming a rest api

我开发了一个 api,想在 mule flow 中使用这个 api。
但是当我从 chrome:postman 进行测试时,出现以下错误。

Message payload is of type: BufferInputStream

所以我尝试记录消息,下面我得到

org.glassfish.grizzly.utils.BufferInputStream@e2ed077

所以基本上我的要求是如何将 json 有效载荷传递给我的 api。下面是我的代码片段。

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8083" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8082" doc:name="HTTP Request Configuration">
    <http:basic-authentication username="sa" password="sa"/>
</http:request-config>
<flow name="get-response-container-storeFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/testapi" doc:name="HTTP"/>
    <logger message="******************Executed Test_Container_Store_API*******************#[payload]" level="INFO" doc:name="Logger"/>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    <http:request config-ref="HTTP_Request_Configuration" path="/apie" method="POST" sendBodyMode="NEVER" doc:name="HTTP">
    </http:request>

您可以通过在 http:inbound 之后(或更重要的是在记录器之前)添加 <object-to-string-transformer/> 作为第一个消息处理器来解决记录器的第一个“错误”。

如果您想在请求中包含正文,您应该从请求中删除 sendBodyMode="NEVER" 属性。

来自 MuleSoft 文档:

By default, the methods GET, HEAD and OPTIONS sends HTTP requests with an empty body, and the payload of the Mule message won’t be used at all. The rest of the methods sends the message payload as the body of the request. If you need to change this default behavior, you can specify the sendBodyMode attribute in the request, with one of the following possible values:

AUTO (default): The behavior depends on the method. Body is not sent for GET, OPTIONS and HEAD, and it is sent otherwise.

ALWAYS: The body is always sent.

NEVER: The body is never sent.

这意味着由于您将此属性设置为 never,因此您的有效负载将永远不会作为 request-body.