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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to