title: Apache HttpClient 4.3.3 how to find target IP of the requested site
body: <p>I have read this one :</p>
  
  <p><a href="http://httpcomponents.10934.n7.nabble.com/get-InetAddress-for-the-HTTP-TARGET-HOST-td18332.html" rel="nofollow">http://httpcomponents.10934.n7.nabble.com/get-InetAddress-for-the-HTTP-TARGET-HOST-td18332.html</a></p>
  
  <p>And I could not figure out how to do the same with the latest Apache HttpClient 4.3.3.
  What I want to do is to obtain the IP of the requested site. I know that this is not possible with the minimal httpclient, but how exactly should it be used?</p>
  
  <p>Since the minimal httpclient has PoolingHttpClientConnectionManager(HttpClientConnectionManager) as argument but not ClientConnectionManager I don't know which methods to override and which attributes to set.
  The example above has direct access to sockets, which is not the case with the new one.</p>
  
  <p>So the question is how to do that with the new (4.3.3) API.
  And how it is correct to keep the already resolved IPs from redirects for example, avoiding
  second DNS resolution.</p>
  
  <p>And a code snippet which approximates the written in the link and which both lines of output are NULL:</p>
  
  <pre><code> public static void main(String[] args) throws ClientProtocolException,
              IOException {
  
          String s = "http://google.com";
  
          PoolingHttpClientConnectionManager m = new PoolingHttpClientConnectionManager(
                  RegistryBuilder.&lt;ConnectionSocketFactory&gt; create()
                          .register("http", new PlainConnectionSocketFactory() {
  
                              @Override
                              public Socket createSocket(HttpContext context)
                                      throws IOException {
                                  Socket s = super.createSocket(context);
                                  context.setAttribute("sock-address",
                                          s.getRemoteSocketAddress());
                                  return s;
                              }
                          }).build(), new SystemDefaultDnsResolver());
  
          CloseableHttpClient minimal = HttpClients.createMinimal(m);
  
          HttpGet get = new HttpGet(s);
  
          HttpClientContext context = HttpClientContext.create();
  
          CloseableHttpResponse response = minimal.execute(get, context);
  
          InetSocketAddress addr = (InetSocketAddress) context
                  .getAttribute("sock-address");
  
          HttpHost target = (HttpHost) context
                  .getAttribute(ExecutionContext.HTTP_TARGET_HOST);
  
          System.out.println(addr);
          System.out.println(target.getAddress());
  
      }
  </code></pre>
  
  <p>And the only maven dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
      &lt;version&gt;4.3.3&lt;/version&gt;
  &lt;/dependency&gt;       
  </code></pre>