hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen J. Butler" <stephen.but...@gmail.com>
Subject Re: Multiple entities in single Post?
Date Fri, 14 Dec 2012 23:55:49 GMT
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 <cory.lum@oracle.com> 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: httpclient-users@hc.apache.org
> 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: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message