HttpComponents —— HTTP上下文环境(HttpContext)
HttpGet httpget =new HttpGet("http://www.baidu.com/");
HttpResponse response = client.execute(httpget, localContext);
HttpHost target = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
System.out.println("Final target: " + target);
HttpEntity entity = response.getEntity();
if (entity !=null) {
EntityUtils.consume(entity);
}
输出:
Final target: http://www.baidu.com