hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Jones <rich...@symplectic.co.uk>
Subject Re: mime-boundary headers
Date Wed, 22 Apr 2009 11:09:31 GMT
Hi Oleg,

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

Ah, I see.  And there's no way that I can override the default 
behaviour?  I need to replace the disposition type with an x- extension 
of my own, unfortunately.

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

I'll take a look at that, thanks.  I understand 4.0 is still in beta, is 
there a timescale for a production release yet?

Cheers,

Richard


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