title: Android: Using resolved IP Address instead of hostname
body: <p>I would want to use resolved IP address to connect to server instead of hostname. Here is my code snippets:</p>
  
  <pre><code>     // Get domain name from URL
      String domainName = url.substring("http://".length(),
              url.indexOf("/", 8));
      // Get IP address as string
      InetAddress inet = null;
      try {
          inet = InetAddress.getByName(domainName);
      } catch (UnknownHostException e) {
          Log.i(TAG, "The IP address cannot be resolved for " + domainName);
      }
          resolvedIP = inet.getHostAddress(); 
  </code></pre>
  
  <p>Here i'm able to successfully get IP ADDRESS. Now i try to replace my url as below:</p>
  
  <pre><code>url = url.replace(domainName, resolvedIP);
  
  Now I connect to server:
  URL download = new URL(url);
  
  
  conn = (HttpURLConnection) url.openConnection();
  
  conn.getInputStream(); //Throws IO Exception
  </code></pre>
  
  <p>I'm able to successfully connect if I use URL as it is (without replacing domain name with IP Address).</p>
  
  <p>Please let me know if I'm doing things correctly.</p>