2010-07-08 67 views

回答

14

您應該在請求中使用Range標頭。但是,只有當服務器通知您它接受Accept-Ranges響應標頭的範圍請求時,您纔可以使用它。

這是一個示例會話。假設我們有興趣獲得this picture的一部分。首先,我們發送HTTP HEAD請求,以確定:a)如果服務器支持字節範圍,b)將內容長度:

> HEAD /2238/2758537173_670161cac7_b.jpg HTTP/1.1 
> Host: farm3.static.flickr.com 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Date: Thu, 08 Jul 2010 12:22:12 GMT 
< Content-Type: image/jpeg 
< Connection: keep-alive 
< Server: Apache/2.0.52 (Red Hat) 
< Expires: Mon, 28 Jul 2014 23:30:00 GMT 
< Last-Modified: Wed, 13 Aug 2008 06:13:54 GMT 
< Accept-Ranges: bytes 
< Content-Length: 350015 

接下來,我們發送GET請求與Range頭要求的前11

> GET /2238/2758537173_670161cac7_b.jpg HTTP/1.1 
> Host: farm3.static.flickr.com 
> Accept: */* 
> Range: bytes=0-10 
> 
< HTTP/1.1 206 Partial Content 
< Date: Thu, 08 Jul 2010 12:26:54 GMT 
< Content-Type: image/jpeg 
< Connection: keep-alive 
< Server: Apache/2.0.52 (Red Hat) 
< Expires: Mon, 28 Jul 2014 23:30:00 GMT 
< Last-Modified: Wed, 13 Aug 2008 06:13:54 GMT 
< Accept-Ranges: bytes 
< Content-Range: bytes 0-10/350015 
< Content-Length: 11 
< 

這是第一個11個字節的十六進制轉儲:

00000000 ff d8 ff e0 00 10 4a 46 49 46 00     |......JFIF.| 
0000000b 

欲瞭解更多信息請參閱的picure字節210在HTTP RFC 2616中。

+1

在範圍標題規範中提到接受範圍是可選的服務器可以接受範圍而沒有提到它有點卷積,但唯一真正的測試是嘗試 – 2010-07-08 13:11:17

+1

@Xavier是,如果服務器不接受範圍,則它可以用406或400狀態碼進行響應。 – 2010-07-08 13:25:52

3

http://www.gnu.org/software/wget/manual/wget.html

注意「-c」僅與FTP 服務器和與 支持Range頭的HTTP服務器的工作原理。

在字節範圍,說明符 值(假定
長度10000的實體主體)的http://tools.ietf.org/html/rfc2616

實例:

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

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

    - The final 500 bytes (byte offsets 9500-9999, inclusive): 
    bytes=-500 

    - Or bytes=9500- 

    - The first and last bytes only (bytes 0 and 9999): bytes=0-0,-1 

    - Several legal but not canonical specifications of the second 

500個 字節(字節偏移500 -999,含): bytes = 500-600,601-999 bytes = 500-700,601-999

所以,你應該送

Range:bytes=9500- 

測試如果服務器支持它,你可以測試接受範圍如此

原始服務器接受字節範圍請求可以發送

接受範圍:字節

但不要求這樣做。客戶端可以生成字節範圍爲 的請求,但未收到涉及的資源 的此標頭。範圍單位在3.12節中定義。不接受任何形式的 資源範圍請求的

服務器可能會發送

Accept-Ranges: none 

勸客戶不要嘗試範圍請求。

相關問題