Java中的Range属性是HttpURLConnections包含还是独占?

时间:2016-03-17 15:24:56

标签: java networking range httpconnection

我正在使用Range从网上抓取对象:

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Range", "bytes=0-1000");

// Parallel in different thread

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Range", "bytes=1000-2000");

// More code that actually collects the data

这是否抓住了第1000个字节两次?或者上限是否排他?

1 个答案:

答案 0 :(得分:1)

这些职位是包容性的。

https://tools.ietf.org/html/rfc7233#section-2.1

  

byte-range-spec中的first-byte-pos值给出了一个范围内第一个字节的字节偏移量。   last-byte-pos值给出范围中最后一个字节的字节偏移量;   也就是说,指定的字节位置是包含的。字节偏移从零开始。