title: Downloading a portion of a File using HTTP Requests
body: <p>I am trying to download a portion of a PDF file (just for testing "Range" header). I requested the server for the bytes (0-24) in Range but still, instead of getting first 25 bytes (a portion) out of the content, I am getting the full length content. Moreover, instead of getting response code as 206 (partial content), I'm getting response code as 200.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public static void main(String a[]) {
      try {
          URL url = new URL("http://download.oracle.com/otn-pub/java/jdk/7u21-b11/jdk-7u21-windows-x64.exe?AuthParam=1372502269_599691fc0025a1f2da7723b644f44ece");
          HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
          urlConnection.setRequestProperty("Range", "Bytes=0-24");
          urlConnection.connect();
  
          System.out.println("Respnse Code: " + urlConnection.getResponseCode());
          System.out.println("Content-Length: " + urlConnection.getContentLengthLong());
  
          InputStream inputStream = urlConnection.getInputStream();
          long size = 0;
  
          while(inputStream.read() != -1 )
              size++;
  
          System.out.println("Downloaded Size: " + size);
  
      }catch(MalformedURLException mue) {
          mue.printStackTrace();
      }catch(IOException ioe) {
          ioe.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Here's the output:<br>
  <code>
  Respnse Code: 200<br>
  Content-Length: 94973848<br>
  Downloaded Size: 94973848</code></p>
  
  <p>Thanks in Advance.</p>