Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 16569 invoked by uid 98); 18 Dec 2002 14:42:48 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 16274 invoked from network); 18 Dec 2002 14:42:42 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 18 Dec 2002 14:42:42 -0000 Received: (qmail 35709 invoked by uid 500); 18 Dec 2002 14:41:02 -0000 Received: (qmail 35667 invoked from network); 18 Dec 2002 14:41:02 -0000 Received: from napis66.naptheon.com (205.128.202.66) by daedalus.apache.org with SMTP; 18 Dec 2002 14:41:02 -0000 Received: by napis66.naptheon.com; id JAA12676; Wed, 18 Dec 2002 09:41:02 -0500 (EST) Received: from mail.nns.com(172.30.10.115) by napis66.naptheon.com via smap (V5.5) id xmaa12301; Wed, 18 Dec 02 09:39:36 -0500 Received: from npeimc02.nns.com ([172.30.18.167]) by nprdeg02. (NAVGW 2.5.1.13) with SMTP id M2002121809393403607 for ; Wed, 18 Dec 2002 09:39:34 -0500 Received: by npeimc02.nns.com with Internet Mail Service (5.5.2653.19) id ; Wed, 18 Dec 2002 09:39:35 -0500 Message-ID: From: "Murphy, Tom (T06)" To: "'Jakarta Commons Users List'" Subject: RE: [HttpClient]Is HttpClient usable? Date: Wed, 18 Dec 2002 09:39:34 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C2A6A3.48896880" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_000_01C2A6A3.48896880 Content-Type: text/plain; charset="iso-8859-1" Grateful for the update. Looking forward to alpha 2. I stumbled into getting HttpClient to successfully forge a multipart/form-data POST request (uploading 2 files) and handle it with Commons' FileUpload. Still not real sure about how HttpClient *should* operate--just looked through the API and tried different things till something worked. I'm attaching a code excerpt for any interested parties. I'm not claiming that it's elegant, secure, or even good, but it did seem to work. Files are sent as application/octet-streams--I didn't see how to manually set content-type. I'll keep experimenting. Thanks again. -----Original Message----- From: Rodney Waldhoff [mailto:rwaldhoff@apache.org] HttpClient is very much usable. The "alpha" state refers much more to design flux (although much of that has been worked through in the past couple of months). HttpClient seems to have rather few bugs for its size and complexity. I'd encourage you to use the nightly builds rather than the "alpha 1" release (you can grab one from ). There's an "alpha 2" release coming in the next few days, and hopefully httpclient is approaching a genuine 2.0 release soon. The current/A2 version is substantially enhanced and should be much closer to what the final 2.0 version looks like than 2.0A1 is. HttpClient does provide support for mulitpart/form-data POSTs, but I'll have to let someone more familiar with that code describe how to use it. On Tue, 17 Dec 2002, Murphy, Tom (T06) wrote: > More specifically: If I want to simulate a multipart/form-data POST request, > should I experiment with HttpClient or look elsewhere? I do realize it's in > alpha form . . . > ------_=_NextPart_000_01C2A6A3.48896880 Content-Type: text/plain; name="MultipartPostGenerator.txt" Content-Disposition: attachment; filename="MultipartPostGenerator.txt" // class attempting to simulate a multipart/form-data POST // uploads 2 files . . . import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.methods.multipart.*; public class MultipartPostGenerator { . . . try { . . . // end target is http://www.serverToPostFilesTo.com/applicationPath/FileUpload int port = 80; String protocol = "http"; String server = "www.serverToPostFileTo.com"; String serverPath = "/applicationPath/FileUpload"; HttpClient httpclient = new HttpClient(); HttpState httpState = httpClient.getState(); HostConfiguration hostConfig = httpClient.getHostConfiguration(); hostConfig.setHost(server, port, protocol); HttpConnection conn = httpState.getHttpConnectionManager().getConnection(hostConfig); MultipartPostMethod multipartPost = new MultipartPostMethod(serverPath); multipartPost.addPart( new FilePart("file1", new File(localPathToFile1)) ); multipartPost.addPart( new FilePart("file2", new File(localPathToFile2)) ); int responseCode = httpClient.executeMethod(multipartPost); bytes[] responseBytes = multipartPost.getResponseBody(); multipartPost.releaseConnection(); // do something with responseCode and/or responseBytes . . . } catch (FileNotFoundException) . . . catch (MalformedURLException) . . . catch (IOException) . . . } // END ------_=_NextPart_000_01C2A6A3.48896880--