Your problem isn't with HttpClient, but rather the HTTP & CGI specs with how forms are posted. Namely, you can't mix both a URL encoded form (application/x-www-form-urlencoded) and a multipart encoded form (multipart/form-data). You get one or the other.
Now suppose you added both values under the same name inside a single MultipartEntity. The Java servlet spec says this is what happens with getParameter(), which isn't what you want: "If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues." That is, the Java servlet spec doesn't handle parameters in the way you would desire. You could use request.getParameterValues() and just pick the last one. However, I don't see anything in the spec that says values in this array must be in the same order they were provided in the request. On Fri, Dec 14, 2012 at 3:44 PM, Cory Lum <[email protected]> wrote: > Just like to add that on server side, I wish to use > request.getParameter("paramname"); > If I use entity.addPart("paramname", new StringBody("paramvalue"), the > above returns null; > > > -----Original Message----- > From: Cory Lum > Sent: Friday, December 14, 2012 4:20 PM > To: [email protected] > Subject: Multiple entities in single Post? > > Hi, > > > > I'm trying to include request parameters and a multipart upload in a > single Post. Is it possible? > > > > HttpPost post = HttpPost(); > > //adding params > > List <NameValuePair> params = .; //assume params > > post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); > > > > //over writes params > > MultipartEntity entity = new > MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); > > entity.addPart(.); //assume data > > post.setEntity(entity); > > > > How to set two type of entities? > > > > Thanks, > > Cory > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
