java - HttpClient 4.1 does not return host value all the time -


if run following code, see uri has value of "null" host upon completion. invalid! should have uri after executing request.

i trying current page context after page requested (in case redirects occurred).

i apologize confusion. mentioned redirect because thought illustrate problem more easily. code below should work pages redirected , not.

plug in favorite site, doesn't matter. final solution has work site... redirected , not.

what missing?

public static void main(string args[]) throws clientprotocolexception, ioexception {     httpparams httpparams = new basichttpparams();     httpclient httpclient = new defaulthttpclient(httpparams);     httpget httpget = new httpget("http://www.google.com/");     httpcontext context = new basichttpcontext();     httpclient.execute(httpget, context);     httpurirequest currentreq = (httpurirequest) context.getattribute(executioncontext.http_request);     system.out.println("new uri host (why null?): " + currentreq.geturi().gethost()); } 

from docs (http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html)

defaulthttpclient httpclient = new defaulthttpclient();  httpcontext localcontext = new basichttpcontext(); httpget httpget = new httpget("http://localhost:8080/");  httpresponse response = httpclient.execute(httpget, localcontext); // here: httphost target = (httphost) localcontext.getattribute(         executioncontext.http_target_host); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -