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 "Andrew A. Sabitov" <sa...@catalysis.nsk.su> on 2005/08/08 07:55:51 UTC

Local IP binding

Hi All!

Could anyone describe me how to bind HttpClient to local IP addr? I mean, 
I have a host with some IPs assigned to it, and I need to send 
http-requests from only one specific IP. 

How can I do it?


-- 
       ,,,,
       /'^'\
      ( o o )
--oOOO--(_)--OOOo------------------------------------------------
|                  Andrew A. Sabitov
|                  Email: sabitov@catalysis.nsk.su
|                  WWW:   fir.catalysis.nsk.su/~sabitov
| .oooO   Еж птица гордая - пока не пнешь, не полетит!
| (   )   Oooo.
---\ (----(   )-------------------------------------------------
    \_)    ) /
          (_/

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


Re: Local IP binding

Posted by "Andrew A. Sabitov" <sa...@catalysis.nsk.su>.
Oleg, thanks a lot!!! It works fine. 

On Mon, 8 Aug 2005, Oleg Kalnichevski wrote:

> Andrew,
> 
> A custom HostConfiguration should also do the trick
> 
> HttpClient httpagent = new HttpClient();
> HostConfiguration hostconf = new HostConfiguration();
> hostconf.setHost("www.yahoo.com");
> hostconf.setLocalAddress(InetAddress.getByAddress(new byte[] {127, 0, 0, 1}));
> HttpMethod method = new GetMethod("/");
> try {
>     httpagent.executeMethod(hostconf, method);
>     if (method.getStatusCode() == HttpStatus.SC_OK) {
>         System.out.println(method.getResponseBodyAsString());
>     } else {
>         System.out.println("Unexpected failure: "
>                 + method.getStatusLine().toString());
>     }
> } finally {
>     method.releaseConnection();
> }
> 
> Hope this helps
> 
> Oleg



-- 
       ,,,,
       /'^'\
      ( o o )
--oOOO--(_)--OOOo------------------------------------------------
|                  Andrew A. Sabitov
|                  Email: sabitov@catalysis.nsk.su
|                  WWW:   fir.catalysis.nsk.su/~sabitov
| .oooO   Еж птица гордая - пока не пнешь, не полетит!
| (   )   Oooo.
---\ (----(   )-------------------------------------------------
    \_)    ) /
          (_/

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


Re: Local IP binding

Posted by Oleg Kalnichevski <ol...@apache.org>.
Andrew,

A custom HostConfiguration should also do the trick

HttpClient httpagent = new HttpClient();
HostConfiguration hostconf = new HostConfiguration();
hostconf.setHost("www.yahoo.com");
hostconf.setLocalAddress(InetAddress.getByAddress(new byte[] {127, 0, 0, 1}));
HttpMethod method = new GetMethod("/");
try {
    httpagent.executeMethod(hostconf, method);
    if (method.getStatusCode() == HttpStatus.SC_OK) {
        System.out.println(method.getResponseBodyAsString());
    } else {
        System.out.println("Unexpected failure: "
                + method.getStatusLine().toString());
    }
} finally {
    method.releaseConnection();
}

Hope this helps

Oleg


On Mon, Aug 08, 2005 at 08:32:44AM +0200, Roland Weber wrote:
> Hi Andrew,
> 
> > Could anyone describe me how to bind HttpClient to local IP addr? I 
> mean, 
> > I have a host with some IPs assigned to it, and I need to send 
> > http-requests from only one specific IP. 
> 
> HttpClient uses a ProtocolSocketFactory to create connections to the 
> server:
> http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html
> 
> By implementing your own protocol socket factory, you should be able to do
> everything socket-specific using the standard Java socket API.
> 
> 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
> 
> 

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


Re: Local IP binding

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Andrew,

> Could anyone describe me how to bind HttpClient to local IP addr? I 
mean, 
> I have a host with some IPs assigned to it, and I need to send 
> http-requests from only one specific IP. 

HttpClient uses a ProtocolSocketFactory to create connections to the 
server:
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html

By implementing your own protocol socket factory, you should be able to do
everything socket-specific using the standard Java socket API.

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