Mule http:outbound-endpoint + multipart/form-data

浪尽此生 提交于 2019-12-04 20:32:51

The following shows how to POST a multipart entity with two field values:

<expression-component><![CDATA[
    ds = new org.mule.message.ds.StringDataSource('key1','value1','text/plain');
    dh = new javax.activation.DataHandler(ds);
    message.outboundAttachments['key1'] = dh;

    ds = new org.mule.message.ds.StringDataSource('key2','value2','text/plain');
    dh = new javax.activation.DataHandler(ds);
    message.outboundAttachments['key2'] = dh;
]]></expression-component>

<set-payload value="#[null]" />

<http:outbound-endpoint exchange-pattern="request-response"
    method="POST" address="http://localhost:8082/path" />

Be careful to not specify a value for contentType otherwise Mule will not be able to provide the multi-part boundary in the POST.

If you happen to have a Content-Type message property in the outbound scope, remove it with:

<remove-property propertyName="Content-Type" />

before the HTTP outbound endpoint.

Only to complement i'm using Anypoint Studio 3.5.2 with mule runtime 3.5.0, the signature of the constructor of the class org.mule.message.ds.StringDataSource is different, rather than:

org.mule.message.ds.StringDataSource ('key1 '' value1 ',' text / plain ');

is

org.mule.message.ds.StringDataSource ('value1', 'key1', 'text / plain');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!