我想使用Mule请求API。它正在使用Multipart / related Content-Type上传文件。我不知道如何在mule中传递边界信息。如何将有效负载中的给定输入设置为发送到HTTP.I试图将它放在转换消息组件中,但它显示错误。
答案 0 :(得分:1)
您可以根据需要使用出站附件集合创建表单部件,而不需要指定边界。
例如,请考虑以下Mule配置:
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[
message.addOutboundAttachment('some-json.json', '{ "name": "My File" }', 'application/json');
message.addOutboundAttachment('myfile.txt', new java.io.File('c:\\myfile.txt'), null);
]]></scripting:script>
</scripting:component>
<http:request config-ref="HTTP_Request_Configuration" path="/" method="POST" doc:name="HTTP"/>
Mule发出的出站HTTP请求是:
POST / HTTP/1.1
Host: localhost:80
User-Agent: AHC/1.0
Connection: keep-alive
Accept: */*
Content-Type: multipart/form-data; boundary=pHSj1qavizuHBv879Hoo_RQ9tFqtAfS9i;charset=UTF-8
Content-Length: 438
--pHSj1qavizuHBv879Hoo_RQ9tFqtAfS9i
Content-Disposition: form-data; name="some-json.json"
Content-Type: application/json
Content-Transfer-Encoding: binary
{ "name": "My File" }
--pHSj1qavizuHBv879Hoo_RQ9tFqtAfS9i
Content-Disposition: form-data; name="myfile.txt"; filename="myfile.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
This is just some random text file...
--pHSj1qavizuHBv879Hoo_RQ9tFqtAfS9i--
希望有所帮助。