title: UnknownHostException when attempting to create a HTTPUrlConnection with a proxy
body: <p>Using Java, I am attempting to connect and fetch the response code from <a href="http://www.oracle.com" rel="nofollow">http://www.oracle.com</a> via a local proxy <a href="http://www-my.proxy.address.com" rel="nofollow">http://www-my.proxy.address.com</a>.</p>
  
  <p>I've tried:</p>
  
  <pre><code>public void testAConnection() throws IOException {
      String urlText = "http://www.oracle.com";
  
      System.setProperty("http.proxyHost", "http://www-my.proxy.address.com");
      System.setProperty("http.proxyPort", "80");
  
      Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("http://www-my.proxy.address.com", 80));
      URL url = new URL(urlText);
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
      int responseCode = conn.getResponseCode();
      System.out.println(responseCode);
  }
  </code></pre>
  
  <p>Which throws:</p>
  
  <pre><code>java.net.UnknownHostException: ...
  </code></pre>
  
  <p>As well as:</p>
  
  <pre><code>Proxy proxy = new Proxy(Proxy.Type.DIRECT, new InetSocketAddress("http://www-my.proxy.address.com", 80));
  URL url = new URL(urlText);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
  </code></pre>
  
  <p>The latter throws: </p>
  
  <p><code>ava.lang.IllegalArgumentException: type DIRECT is not compatible with address ...</code> </p>
  
  <p>For others who have solved this problem, the second method seems to usually work. Any help appreciated!</p>
  
  <p><strong>EDIT: After racking my brains trying to figure what was wrong, I restarted my IDE and everything seems to be working. Thanks for your feedback.</strong></p>