You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mukesh Garg <Mu...@Sun.COM> on 2007/12/02 14:04:44 UTC

POST method problem(if read a request parameter)

Hi All,

I am having a strange issue while using HttpPost method.

I am using HttpPostMehod to send a Http Post request to an external 
server. My servlet is just proxy to the external server.

My code is something like this.


HttpServletRequest request

HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);

post.setRequestEntity(new InputStreamRequestEntity(request.getInputStream());

This work perfectly file.

But if I read any request parameter from the request before executing the request, even If I don't do any thing else with the request and irrespective of the parameter existing or not. I just add this line before executing the post request "request.getParameter("xyz")".
The Post request fails with the addition of this line . I get Response code of 400 from the external server.

I don't not have access to the external server, so I can't see what 
might be wrong. But this is quite strange behavior. I need access the 
above said request parameter in my servlet for some validation.

Could anybody suggest what might be going wrong or if there is something 
I am doing wrong ?

Any help is much appreciated.

regards,
Mukesh

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: POST method problem(if read a request parameter)

Posted by Roland Weber <os...@dubioso.net>.
Hello Mukesh,

> HttpServletRequest request
> 
> But if I read any request parameter from the request before executing
> the request, [...] The Post request fails [...]

If you call HttpServletRequest.getParameter(), the servlet
container will read the request entity to merge the parameters
sent in the body with the query parameters in the URL.

> I don't not have access to the external server, so I can't see what
> might be wrong. But this is quite strange behavior. I need access the
> above said request parameter in my servlet for some validation.

If it's a query parameter you need, try to obtain the URL
from the servlet request and get the parameter from there.
Otherwise, use HttpServletRequest.getParameter() and create
a new request entity from the parameters when forwarding
the request, instead of using getInputStream().

hope that helps,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org