hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Telvis Calhoun Jr." <telvi...@gmail.com>
Subject get InetAddress for the HTTP_TARGET_HOST
Date Fri, 13 Jul 2012 16:15:13 GMT
How do I get the InetAddress for the HttpHost returned by
ExecutionContext.HTTP_TARGET_HOST? I'm trying to get the destination
IP address after redirects. A work-around is to call
InetAddress.getByName() using the target host but I assume HttpClient
already does this.

// Code
 HttpClient httpclient = new DefaultHttpClient();
 HttpHead httphead = new HttpHead("http://bit.ly/xxxxxx");
 HttpContext localContext = new BasicHttpContext();
 HttpResponse response = httpclient.execute(httphead, localContext);
 HttpHost target = (HttpHost)
 System.out.println("Final target: " + target.toHostString());

/* work-around using InetAddress.getByName */
 InetAddress addr = InetAddress.getByName(target.toHostString());
 System.out.printf("addr: %s\n", addr.getHostAddress());


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

View raw message