hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: mime-boundary headers
Date Wed, 22 Apr 2009 09:41:43 GMT
On Tue, Apr 21, 2009 at 04:09:13PM +0100, Richard Jones wrote:
> Hi Folks,
>
> Apologies if this is a newbie question; I'm a long time user of  
> httpclient for basic purposes, but am being stumped this week by a more  
> difficult requirement, and wonder if anyone can help.
>
> I need to assemble a multi-part request, consisting of some normal http  
> headers, an xml document in the first mime-part, and a binary document  
> in the second mime-part.  I need to augment the mime-parts with their  
> own http headers, also; specifically a Content-Type declaration and a  
> Content-Disposition header for each one (which I believe is allowed by  
> the MIME standard, from what I can discern from the rfc).  My current  
> code looks like this:
>
> HttpClient client = new HttpClient();
> PostMethod post = new PostMethod(target);
>
> // set the request headers
> post.setRequestHeader("Slug", slug);
> post.setRequestHeader("X-On-Behalf-Of", user);
>
> // construct the xml and binary file parts
> FilePart xmlPart = new FilePart("atom", new File(xml), "text/xml", null);
> FilePart binaryPart = new FilePart("binary", new File(binary));
>
> // make the multipart request body
> Part[] parts = { xmlPart, binaryPart };
> MultipartRequestEntity re = new MultipartRequestEntity(parts,  
> post.getParams());
> post.setRequestEntity(re);
>
> // execute the post
> client.executeMethod(post);
>
> As you can see, I've got the Content-Type header being set properly in  
> the FilePart constructor, and this works fine.  What I can't figure out  
> how to do is add the Content-Disposition header to either of these  
> parts.  I've poked around the examples, tutorials and mailing lists but  
> haven't been able to find any examples of this, but I have seen  
> references in the source code to the content disposition in the Part  
> object from which FilePart eventually extends.
>
> Any help or pointers to documentation gratefully appreciated.
>
> All the best,
>
> Richard
>

Hi Richard,

The Content-Disposition header will be automatically generated by HttpClient.
If you want a greater control over the process of MIME content generation,
please consider upgrading to HttpClient 4.0 which has much improved MIME
capabilities based on Apache mime4j.

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpmime/src/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java

Hope this helps

Oleg


> -- 
> Richard Jones
> Head Repository Systems Architect, Symplectic Limited
> e: richard@symplectic.co.uk
> t: 0845 026 4755
> t: +44 (0)207 7334036
> w: http://www.symplectic.co.uk/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message