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 angelogeminiani <an...@gmail.com> on 2011/09/02 17:22:00 UTC
HttpServer: How to get Client IP
Hi,
I'm writing an HTTP server and I need client IP.
I'm using httpcore 4.1.3.
In Servlets it's easy: request.getRemoteAddr().
Is there similar method in HttpRequest, or a way to retrieve client IP from
server?
--
View this message in context: http://old.nabble.com/HttpServer%3A-How-to-get-Client-IP-tp32387476p32387476.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: HttpServer: How to get Client IP
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2011-09-04 at 06:24 -0700, angelogeminiani wrote:
>
>
> olegk wrote:
> >
> > On Fri, 2011-09-02 at 08:22 -0700, angelogeminiani wrote:
> >> Hi,
> >> I'm writing an HTTP server and I need client IP.
> >> I'm using httpcore 4.1.3.
> >> In Servlets it's easy: request.getRemoteAddr().
> >> Is there similar method in HttpRequest, or a way to retrieve client IP
> >> from
> >> server?
> >>
> >
> > You can cast any instance of the HttpConnection interface to
> > HttpInetConnection in order to get access to IP address of its
> > endpoints:
> >
> > http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpInetConnection.html
> >
> > Oleg
> >
>
> Thank you Olegk for your help.
> I'm writing a server starting from
> http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/examples/org/apache/http/examples/nio/NHttpServer.java
> and need Client IP in file handler.
> Where can I get a HttpConnection instance?
> Is there any in HttpRequest?
> I need IP of client in HttpFileHandler.
> Thak you.
>
You can obtain the underlying connection from the HTTP context using
ExecutionContext#HTTP_CONNECTION as a key.
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: HttpServer: How to get Client IP
Posted by angelogeminiani <an...@gmail.com>.
olegk wrote:
>
> On Fri, 2011-09-02 at 08:22 -0700, angelogeminiani wrote:
>> Hi,
>> I'm writing an HTTP server and I need client IP.
>> I'm using httpcore 4.1.3.
>> In Servlets it's easy: request.getRemoteAddr().
>> Is there similar method in HttpRequest, or a way to retrieve client IP
>> from
>> server?
>>
>
> You can cast any instance of the HttpConnection interface to
> HttpInetConnection in order to get access to IP address of its
> endpoints:
>
> http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpInetConnection.html
>
> Oleg
>
Thank you Olegk for your help.
I'm writing a server starting from
http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/examples/org/apache/http/examples/nio/NHttpServer.java
and need Client IP in file handler.
Where can I get a HttpConnection instance?
Is there any in HttpRequest?
I need IP of client in HttpFileHandler.
Thak you.
--
View this message in context: http://old.nabble.com/HttpServer%3A-How-to-get-Client-IP-tp32387476p32395852.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: HttpServer: How to get Client IP
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2011-09-02 at 08:22 -0700, angelogeminiani wrote:
> Hi,
> I'm writing an HTTP server and I need client IP.
> I'm using httpcore 4.1.3.
> In Servlets it's easy: request.getRemoteAddr().
> Is there similar method in HttpRequest, or a way to retrieve client IP from
> server?
>
You can cast any instance of the HttpConnection interface to
HttpInetConnection in order to get access to IP address of its
endpoints:
http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpInetConnection.html
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org