Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 2472 invoked from network); 23 Apr 2009 14:16:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Apr 2009 14:16:10 -0000 Received: (qmail 84705 invoked by uid 500); 23 Apr 2009 14:16:09 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 84674 invoked by uid 500); 23 Apr 2009 14:16:09 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 84618 invoked by uid 99); 23 Apr 2009 14:16:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2009 14:16:09 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 67.15.189.26 is neither permitted nor denied by domain of richard@symplectic.co.uk) Received: from [67.15.189.26] (HELO delta.wiserhosting.co.uk) (67.15.189.26) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2009 14:16:01 +0000 Received: from 112.29.169.217.in-addr.arpa ([217.169.29.112] helo=richard-jones-computer.local) by delta.wiserhosting.co.uk with esmtpa (Exim 4.69) (envelope-from ) id 1Lwzi9-0007p2-Gp for httpclient-users@hc.apache.org; Thu, 23 Apr 2009 15:15:33 +0100 Message-ID: <49F07807.70605@symplectic.co.uk> Date: Thu, 23 Apr 2009 15:15:35 +0100 From: Richard Jones User-Agent: Thunderbird 2.0.0.21 (Macintosh/20090302) MIME-Version: 1.0 To: HttpClient User Discussion Subject: Re: mime-boundary headers References: <49EDE199.5060909@symplectic.co.uk> <20090422094143.GA22820@ok2cons2.nine.ch> <49F035E7.4050308@symplectic.co.uk> <20090423114147.GB17431@ok2cons2.nine.ch> In-Reply-To: <20090423114147.GB17431@ok2cons2.nine.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - delta.wiserhosting.co.uk X-AntiAbuse: Original Domain - hc.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - symplectic.co.uk X-Virus-Checked: Checked by ClamAV on apache.org Hi Oleg, >>> 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); >> >> post.setEntity(reqEntity); >> 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? >> >> > > You will have to subclass FormBodyPart class and override its > #generateContentDisp() method. You will also have to implement a custom > HttpEntity similar to MultipartEntity shipped with HttpMime, which makes use of > the extended FormBodyPart class. > OK, I think I'm part way there. After taking a look at the source for FormBodyPart, I came up with this, which I think means that I don't actually have to extend that class: FileBody binBody = new FileBody(new File(binary)); FormBodyPart fb = new FormBodyPart("binary", binBody); fb.getHeader().removeFields(MIME.CONTENT_DISPOSITION); fb.getHeader().addField(new MinimalField(MIME.CONTENT_DISPOSITION, "my-custom-disposition")); Now all I need to do is get the FormBodyPart into the request, which is where I'm now stuck. Obviously, the MultipartEntity doesn't take the FormBodyPart as an argument to addPart(), although it sounds like it should. Is this what you are suggesting I need to implement for HttpEntity, above? Or is there some other way of getting this formbodypart into the request? If I have some feedback for the httpclient 4.0 version, I'd say that this is a particularly challenging and circuitous bit of coding to achieve a relatively minor actual change in the http request. An API to do this sort of thing, without needing custom implementations of http client interfaces would be really useful. Cheers, Richard --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org