I am trying to download part of a PDF file (only for testing the Range header). I requested a server for bytes (0-24) in Range, but instead of getting the first 25 bytes (part) from the content, I get full-sized content. Moreover, instead of getting the response code as 206 (partial content), I get a 200 response code.
Here is my 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(); } }
Here's the conclusion:
Respnse Code: 200
Content-Length: 94973848
Downloaded Size: 94973848
Thanks at Advance.
source share