如何在Mule中传递多部分/相关请求? [英] How to pass multipart/related request in Mule?

查看:143
本文介绍了如何在Mule中传递多部分/相关请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Mule请求API,它使用Multipart/相关的Content-Type上传文件.我不知道如何在Mule中传递边界信息.如何在有效负载中将给定输入设置为发送到HTTP.我试图将其放入转换消息组件中,但显示错误.

I want to request an API using Mule.It is using Multipart/related Content-Type to upload a file.I Don't know how to pass the boundary information in mule.How to set the given input in a payload to send to HTTP.I tried to put it in a transform Message component but it showing errors.

推荐答案

您可以根据需要使用出站附件集合创建表单部件,而无需指定边界.

You can use the outbound attachments collection to create the form parts as necessary, and don't need to specify the boundary.

例如,考虑以下Mule配置:

For example, consider the following Mule configuration:

<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请求是:

The outbound HTTP request which Mule issues is:

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--

希望有帮助.

这篇关于如何在Mule中传递多部分/相关请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆