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 Mario Pavlov <fr...@abv.bg> on 2011/02/18 21:46:07 UTC

HttpCore - getting POST parameters

Hi,
I'm trying to create a simple HTTP server with HttpCore 4.1 but I can't figure out how to get parameters from HTTP POST requests. For instance I want to handle the POST request generated by this HTML code:
<form action="/login" method="POST">
     <input type="text" name="user" />
     <input type="password" name="pass" />
</form>
I have an implementation of HttpRequestHandler and in my 
void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException
I have something like this:
request.getParams().getParameter("user")
which returns null...
I guess HttpParams is something different than what I think it is?
Is what I'm trying to do supported? And if yes, what's the right way to do it?

thank you.

regards,
mgp


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


Re: HttpCore - getting POST parameters

Posted by LongkerDandy <lo...@gmail.com>.
Hi

If a client send a request like "http://example.org/path/to/file?a=1&b=2&c=3
".
How do I get name / value pairs from that.

Frankly, I don't know how to get HttpEntity from the RequestHandler.
I tried request.getRequestLine().getUri(), but it only returned the path
part, like "/file".

Thanks
LongkerDandy

On Sat, Feb 19, 2011 at 6:40 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2011-02-18 at 22:46 +0200, Mario Pavlov wrote:
> > Hi,
> > I'm trying to create a simple HTTP server with HttpCore 4.1 but I can't
> figure out how to get parameters from HTTP POST requests. For instance I
> want to handle the POST request generated by this HTML code:
> > <form action="/login" method="POST">
> >      <input type="text" name="user" />
> >      <input type="password" name="pass" />
> > </form>
> > I have an implementation of HttpRequestHandler and in my
> > void handle(HttpRequest request, HttpResponse response, HttpContext
> context) throws HttpException, IOException
> > I have something like this:
> > request.getParams().getParameter("user")
> > which returns null...
> > I guess HttpParams is something different than what I think it is?
>
> Yes, it is. Those are parameters that define protocol specific aspects
> (such as HTTP version, etc) and not form parameters
>
>
> > Is what I'm trying to do supported? And if yes, what's the right way to
> do it?
> >
>
> HttpCore is a set of low level HTTP transport components and as such
> does not provide methods for processing content. You can, however, use
> URLEncodedUtils class from HttpClient to parse an HTTP entity into a set
> of name / value pairs.
>
> Hope this helps
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

Re: HttpCore - getting POST parameters

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2011-02-18 at 22:46 +0200, Mario Pavlov wrote:
> Hi,
> I'm trying to create a simple HTTP server with HttpCore 4.1 but I can't figure out how to get parameters from HTTP POST requests. For instance I want to handle the POST request generated by this HTML code:
> <form action="/login" method="POST">
>      <input type="text" name="user" />
>      <input type="password" name="pass" />
> </form>
> I have an implementation of HttpRequestHandler and in my 
> void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException
> I have something like this:
> request.getParams().getParameter("user")
> which returns null...
> I guess HttpParams is something different than what I think it is?

Yes, it is. Those are parameters that define protocol specific aspects
(such as HTTP version, etc) and not form parameters


> Is what I'm trying to do supported? And if yes, what's the right way to do it?
> 

HttpCore is a set of low level HTTP transport components and as such
does not provide methods for processing content. You can, however, use
URLEncodedUtils class from HttpClient to parse an HTTP entity into a set
of name / value pairs.

Hope this helps

Oleg



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