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 Thu, 23 Apr 2009 09:33:27 GMT

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

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

I have upgraded my client to using httpclient 4.0 beta 2 with the same 
version of httpmime and httpcore, but am stuck on where in the API I can 
now set my custom Content-Disposition.

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

Following this example, I have re-written my code as follows:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(target);

// set the request headers
post.setHeader("Slug", slug);
post.setHeader("X-On-Behalf-Of", user);

// construct the xml and binary file parts
FileBody xmlBody = new FileBody(new File(xml));
FileBody binBody = new FileBody(new File(binary));

MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("atom", xmlBody);
reqEntity.addPart("binary", binBody);

HttpResponse response = client.execute(post);

But I still don't see any way of passing in http headers for the mime 
parts.  I presume that I'm missing something fundamental about how to 
use httpclient 4 with the httpmime extension, but I can't find any 
examples of doing what it is that i'm trying to do to follow.

What am I missing?

Thanks again,


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

View raw message