title: URL is accessable with browser but still FileNotFoundException with URLConnection
body: <p>I use a HttpURLConnection to connect to a website and receive an ResponseCode=404 (HTTP_NOT_FOUND). However I have no problem opening the website in my browser (IE).</p>
  
  <p>Why the difference, and what can I do about it?</p>
  
  <p>Regards, Pavan</p>
  
  <p>This is my Program</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.net.URLConnection;
  
  public class TestGet {
      private static URL source;
  
      public static void main(String[] args) {
          doGet();
      }
  
      public static void doGet() {
          try {
              source = new URL("http://localhost:8080/");
  
              System.out.println("Url is" + source.toString());
  
              URLConnection connection = source.openConnection();
              connection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
              connection.setRequestProperty("Accept","*/*");
              connection.setDoInput(true);
              connection.setDoOutput(true);
  
              System.out.println(((HttpURLConnection) connection).getResponseCode());
              BufferedReader rdr = new BufferedReader(new InputStreamReader(
                      connection.getInputStream()));
              StringBuffer b = new StringBuffer();
              String line = null;
              while (true) {
                  line = rdr.readLine();
                  if (line == null)
                      break;
                  b.append(line);
              }
  
          } catch (Exception e) {
              e.printStackTrace();
              System.err.println(e.toString());
          }
      }
  
  }
  </code></pre>
  
  <p>Stack Trace</p>
  
  <pre><code>Url ishttp://localhost:8080/
  404
  java.io.FileNotFoundException: http://localhost:8080/
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at TestGet.doGet(TestGet.java:28)
      at TestGet.main(TestGet.java:11)
  Caused by: java.io.FileNotFoundException: http://localhost:8080/
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at java.net.HttpURLConnection.getResponseCode(Unknown Source)
      at TestGet.doGet(TestGet.java:26)
      ... 1 more
  java.io.FileNotFoundException: http://localhost:8080/
  </code></pre>