DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20744>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20744 HTTPClient MultiPartPostMethod inconsistent behaviour compared to standard form upload ------- Additional Comments From [EMAIL PROTECTED] 2003-06-16 13:08 ------- As far as I can tell, FileUpload's current CVS snapshot can parse requests generated with HttpClient just fine. These are the server-side & client-side components I used to test 'multipart/form-data' encoded POST requests: -- Server side -- import java.io.IOException; import java.io.Writer; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.DefaultFileItemFactory; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUpload; import org.apache.commons.fileupload.FileUploadException; public class TestServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); Writer out = response.getWriter(); FileUpload upload = new FileUpload(new DefaultFileItemFactory()); if (FileUpload.isMultipartContent(request)) { try { out.write("Field name\tContent Type\r\n"); List items = upload.parseRequest(request); for (int i = 0; i < items.size(); i++) { FileItem item = (FileItem)items.get(i); out.write(item.getFieldName()); out.write("\t"); out.write(item.getContentType()); out.write("\r\n"); } } catch(FileUploadException e) { throw new ServletException(e); } } else { out.write("Multipart POST request expected"); } out.flush(); } } -- Client side -- import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.methods.multipart.*; public class Test { public static void main(String args[]) throws Exception { HttpClient httpclient = new HttpClient(); MultipartPostMethod httppost = new MultipartPostMethod("http://localhost:8080/test/upload"); httppost.addPart(new StringPart("param1", "value1", "UTF-8")); httppost.addPart(new StringPart("param2", "value2", "US-ASCII")); httppost.addPart(new StringPart("param3", "value3", "ISO-8859-1")); httpclient.executeMethod(httppost); System.out.println(httppost.getStatusLine().toString()); System.out.println(httppost.getResponseBodyAsString()); } } -- Wire log -- [DEBUG] wire - ->> "POST /test/upload HTTP/1.1[\r][\n]" [DEBUG] wire - ->> "User-Agent: Jakarta Commons-HttpClient/2.0beta1[\r][\n]" [DEBUG] wire - ->> "Host: localhost:8080[\r][\n]" [DEBUG] wire - ->> "Content-Length: 567[\r][\n]" [DEBUG] wire - ->> "Content-Type: multipart/form-data; boundary=----------------314159265358979323846[\r][\n]" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "--" [DEBUG] wire - ->> "----------------314159265358979323846" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Disposition: form-data; name=" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "param1" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Type: " [DEBUG] wire - ->> "text/plain" [DEBUG] wire - ->> "; charset=" [DEBUG] wire - ->> "UTF-8" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Transfer-Encoding: " [DEBUG] wire - ->> "8bit" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "value1" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "--" [DEBUG] wire - ->> "----------------314159265358979323846" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Disposition: form-data; name=" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "param2" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Type: " [DEBUG] wire - ->> "text/plain" [DEBUG] wire - ->> "; charset=" [DEBUG] wire - ->> "US-ASCII" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Transfer-Encoding: " [DEBUG] wire - ->> "8bit" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "value2" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "--" [DEBUG] wire - ->> "----------------314159265358979323846" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Disposition: form-data; name=" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "param3" [DEBUG] wire - ->> """ [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Type: " [DEBUG] wire - ->> "text/plain" [DEBUG] wire - ->> "; charset=" [DEBUG] wire - ->> "ISO-8859-1" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "Content-Transfer-Encoding: " [DEBUG] wire - ->> "8bit" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "value3" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - ->> "--" [DEBUG] wire - ->> "----------------314159265358979323846" [DEBUG] wire - ->> "--" [DEBUG] wire - ->> "[\r][\n]" [DEBUG] wire - -<< "HTTP/1.1 200 OK[\r][\n]" [DEBUG] wire - -<< "Content-Type: text/plain[\r][\n]" [DEBUG] wire - -<< "Transfer-Encoding: chunked[\r][\n]" [DEBUG] wire - -<< "Date: Mon, 16 Jun 2003 12:54:23 GMT[\r][\n]" [DEBUG] wire - -<< "Server: Apache Coyote/1.0[\r][\n]" [DEBUG] wire - -<< "8" [DEBUG] wire - -<< "7" [DEBUG] wire - -<< "[\r]" [DEBUG] wire - -<< "[\n]" [DEBUG] wire - -<< "Field name[0x9]Content Type[\r][\n]" [DEBUG] wire - -<< "param1[0x9]text/plain; charset=UTF-8[\r][\n]" [DEBUG] wire - -<< "param2[0x9]text/plain; charset=US-ASCII[\r][\n]" [DEBUG] wire - -<< "param3[0x9]text/plain; charset=ISO-8859-1[\r][\n]" [DEBUG] wire - -<< "[\r]" [DEBUG] wire - -<< "[\n]" [DEBUG] wire - -<< "0" [DEBUG] wire - -<< "[\r]" [DEBUG] wire - -<< "[\n]" [DEBUG] wire - -<< "[\r]" [DEBUG] wire - -<< "[\n]" --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
