title: Response from HttpURLConnection different from curl response
body: <p>I am trying to get response from HttpURLConnection but it throws java.io.FileNotFoundException.</p>
  
  <p>HttpURLConnection : </p>
  
  <pre><code>/**
  * Call URL using HttpURLConnection
  *
  * @param url - the URL to be called
  **/
  public static String getHUCResponse(String url) throws IOException {
  
      InputStream inps = null;
      String res = "";
      try {
  
          URL getURL = new URL(url);
  
          HttpURLConnection huc =  ( HttpURLConnection )  getURL.openConnection ();
          huc.setConnectTimeout(60000); // 1 minute
          huc.setReadTimeout(60000); // 1 minute
  
          huc.setRequestMethod("GET");
  
          inps = huc.getInputStream(); // throws java.io.FileNotFoundException
          res = IOUtils.toString(inps,"UTF8");
      } 
      catch (IOException except){
          throw except;
      }       
      finally {
          IOUtils.closeQuietly(inps);
      }
  
      return res;
  }
  </code></pre>
  
  <p>Error trace:</p>
  
  <pre><code>    java.io.FileNotFoundException: url
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1401)
          at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
          at HttpUtils.getHUCResponse(HttpUtils.java:440)
  </code></pre>
  
  <p>curl: </p>
  
  <pre><code>    $ curl url
      user not found
  
      $ curl -I url
      HTTP/1.1 404 Not Found
      Server: nginx/1.4.2
      Date: Sat, 26 Oct 2013 23:45:20 GMT
      Content-Length: 14
      Connection: keep-alive
  </code></pre>
  
  <p>I expected to get "user not found" as response from HttpURLConnection since this is what is being returned with 404 error.</p>
  
  <p>What could I be missing?</p>
  
  <p>Thanks.</p>