我必须向外部 API 发送多部分/混合请求,并且我构建了一个 Mule 4 流程,其中端点配置为接收多部分/混合有效负载。我创建的端点应该接受多部分/混合有效负载,其中有效负载如下所示,如邮递员屏幕中所示。
以下是流程 xml:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP_Listener_config" doc:id="d8e92a34-d34d-4e1a-abec-7405b9010241">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="testmultipart-flow" doc:id="d8e92a34-d34d-4e1a-bce3-7405b9010241">
<http:listener doc:name="Listener" doc:id="88476dbb-04af-429d-83f3-20714be8d406" config-ref="HTTP_Listener_config" path="/multi" outputMimeType="multipart/mixed; boundary=batch" />
<logger level="INFO" doc:name="Logger" doc:id="ccde0f6d-cc70-4b05-a68c-60f644381b1e" message="Payload: #[payload]" />
<ee:transform doc:name="Multipart payload" doc:id="bfeeab27-6f01-4ea1-a46a-1a65c5aa0021">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
下面是我正在发出的 POST 请求的curl 代码片段:
curl --location 'http://0.0.0.0:8081/multi/' \
--header 'Content-Type: multipart/mixed; boundary=batch' \
--header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
--data '--batch
Content-Type: application/http
Content-Transfer-Encoding: binary
GET TDTREESET?$filter=(Field1%20eq%20'\''213123'\'')&format=xml HTTP/1.1
--batch-'
当我发出请求时,Mule 流正在接收空负载。我尝试对其进行调试,发现在 Mule 调试模式下没有任何有效负载进入。我尝试在流侦听器中将 Mime 类型设置为 multipart/mixed,将边界设置为“batch”,但仍然没有收到有效负载中的任何内容。
payload =
^mediaType = multipart/mixed; charset=UTF-8; boundary=batch
这是我在流程结束时收到的错误。
"javax.mail.internet.ParseException - Missing start boundary
javax.mail.internet.ParseException: Missing start boundary...
如何获取我在请求中以原始文本形式发送的有效负载(如我的 Mule 流中的有效负载)以及为什么即使我设置了边界也会收到此错误?
我使用的Mule运行时版本是4.4.0-20211227
对我来说工作正常,但我使用的是 Mule 4.4.0-20230724。也许您的版本缺少处理此用例的补丁。尝试使用 Mule 的最新补丁或最新次要版本。
HTTP 响应正文
{
"parts": {
"part0": {
"headers": {
"Content-Type": "application/http",
"Content-Transfer-Encoding": "binary"
},
"content": "GET TDTREESET?$filter=(Field1%20eq%20'213123')&format=xml HTTP/1.1\n\n--batch-"
}
}
}
顺便说一句,
outputMimeType="multipart/mixed; boundary=batch"
似乎是多余的,因为请求已经设置了该内容类型。