Roland, Thanks for replying. I believe I discovered the root of my problem, which caused me to try all sorts of things that got me into even more trouble, including the parameter issue that you pointed out. I found that uploading any file of more than a few bytes caused the following exception:
org.apache.commons.httpclient.HttpRecoverableException: java.net.SocketException: Software caused connection abort: socket write error It turned out that the the server I was hitting (Weblogic 9.1) was rejecting the request prematurely unless I added the Expect-Continue header to my request, as in: post.getParams().setParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); After that, everything worked fine. Thanks again, Jeff -----Original Message----- From: Roland Weber [mailto:[EMAIL PROTECTED] Sent: Friday, October 27, 2006 1:47 PM To: HttpClient User Discussion Subject: Re: multipart post problem Hello Jeffrey, > public static void main(String[] args) { > .... > > PostMethod post = new PostMethod(servletPath); > > try { > File tempFile = new File("C:\\0.txt"); > > List<Part> parts = new ArrayList<Part>(); > parts.add(new FilePart("file", tempFile.getName(), tempFile)); > MultipartRequestEntity multipartRequestEntity = new > MultipartRequestEntity(parts.toArray(new Part[0]), post.getParams()); > post.setRequestEntity(multipartRequestEntity); > post.setContentChunked(true); > post.setRequestHeader("Content-type", "multipart/form-data"); > post.setRequestHeader("Content-length", "" + > multipartRequestEntity.getContentLength()); Do not add either of them. > > // add parameters > post.addParameter("description", "desc"); > ... Here, you are *replacing* the multipart request entity by a simple URL-encoded description=desc name-value-pair. It's either one or the other, multipart request entity or parameters. Add your name- value-pairs to the multipart request entity, that's why it's called multipart :-) cheers, Roland --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
