开发者

HttpURLConnection java range

开发者 https://www.devze.com 2023-03-12 09:10 出处:网络
I use \'HttpURLConnection\' in Java with the \"Range\" property to download a segment of a file, i set the range 60000-5600开发者_运维技巧00, and i can read 500000 bytes data,which is 560000-60000. Bu

I use 'HttpURLConnection' in Java with the "Range" property to download a segment of a file, i set the range 60000-5600开发者_运维技巧00, and i can read 500000 bytes data, which is 560000-60000. But when the range is 0-60000, i can read 60001 bytes data, which does not equal 60000-0.

Why? Can anybody give me some explanation?


This is correct behaviour. Both bounds of the range are inclusive. From RFC 7233:

The first-byte-pos value in a byte-range-spec gives the byte-offset of the first byte in a range. The last-byte-pos value gives the byte-offset of the last byte in the range; that is, the byte positions specified are inclusive. Byte offsets start at zero.

Examples of byte-ranges-specifier values:

o The first 500 bytes (byte offsets 0-499, inclusive):

   bytes=0-499

o The second 500 bytes (byte offsets 500-999, inclusive):

   bytes=500-999
0

精彩评论

暂无评论...
验证码 换一张
取 消