title: Use IP and host with Jsoup
body: <p>I would like to access a webpage using ip and host, in order to save DNS lookup times by having stored values for domains. If via sockets, it'd be done by using sockets, transmitting a GET request of the following syntax:</p>
  
  <pre><code>Socket s = new Socket([string_ip_address], 80);
  </code></pre>
  
  <p>Then transmitting:
  Get [file_name] HTTP/1.1\r\n
  Host: [some_name]</p>
  
  <p>But I would like to use Jsoup.
  The equivalent command to retrieve a page, saw www.google.com, in Jsoup is:</p>
  
  <pre><code>Jsoup.connect("http://www.google.com").get();
  </code></pre>
  
  <p>But the provided site name must be the actual name, not IP (because, if my limited understanding is correct, many domains can reside in the same ip address). So, I figured I might try and alter the request made by Jsoup, to include both site name and ip. Since Jsoup uses HttpUrlConnection in it's underlying code (here's a code scrap from the Jsoup library itself, as found here: <a href="https://github.com/jhy/jsoup/blob/master/src/main/java/org/jsoup/helper/HttpConnection.java" rel="nofollow">https://github.com/jhy/jsoup/blob/master/src/main/java/org/jsoup/helper/HttpConnection.java</a>):</p>
  
  <pre><code>HttpURLConnection conn = (HttpURLConnection) req.url().openConnection();
  
  conn.setRequestMethod(req.method().name());
  conn.setInstanceFollowRedirects(false);
  conn.setConnectTimeout(req.timeout());
  conn.setReadTimeout(req.timeout());
  
  if (conn instanceof HttpsURLConnection) {
      if (!req.validateTLSCertificates()) {
           initUnSecureTSL();
           ((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
           ((HttpsURLConnection)conn).setHostnameVerifier(getInsecureVerifier());
      }
  }
  
  if (req.method().hasBody())
      conn.setDoOutput(true);
  if (req.cookies().size() &gt; 0)
      conn.addRequestProperty("Cookie", getRequestCookieString(req));
  for (Map.Entry&lt;String, String&gt; header : req.headers().entrySet()) {
      conn.addRequestProperty(header.getKey(), header.getValue());
  }
  </code></pre>
  
  <p>I thought about writing something like this:</p>
  
  <pre><code>Jsoup.connect(ip).header("Host", host);
  </code></pre>
  
  <p>But this doesn't seem to work.
  So, is there a known way to use ip + host in Jsoup requests (to spare DNS lookups), or is there some other way to skip the DNS lookup using Jsoup? </p>
  
  <p>Thanks!</p>
  
  <p>EDIT - </p>
  
  <p>Just to be clear: 
  Using sockets with IP and host name - works. For example, trying to fetch the main page of buzzfeed via IP in the following way:</p>
  
  <pre><code>Socket s = new Socket("23.34.229.118", 80);
  BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
  PrintStream writer = new PrintStream(s.getOutputStream());
  writer.println("GET / HTTP/1.0\r\nHost: www.buzzfeed.com\r\n");
  
  String line;
  while((line = reader.readLine()) != null)
  {
      System.out.println(line);
  }
  
  s.close();
  </code></pre>
  
  <p>Works perfectly fine. But I am unable to access the page via </p>
  
  <pre><code>Jsoup.connect("http://23.34.229.118");
  </code></pre>
  
  <p>And I am quite sure that's because I need to specify the host somehow, if that's even possible. My attempt with </p>
  
  <pre><code>Jsoup.connect("http://23.34.229.118").header("Host", "buzzfeed.com"); 
  </code></pre>
  
  <p>failed and I got a 400 error.</p>