代码之家  ›  专栏  ›  技术社区  ›  Mykola Kharechko

从服务器读取带有某些偏移量的文件

  •  7
  • Mykola Kharechko  · 技术社区  · 15 年前

    工作组-c )? 我必须发送哪些邮件头到服务器?服务器必须支持什么未来?

    2 回复  |  直到 15 年前
        1
  •  16
  •   Andrey Vlasovskikh    15 年前

    你应该使用 Range 请求中的标头。但只有当服务器通知您它接受范围请求时,您才可以使用它 Accept-Ranges

    这是一个示例会话。假设我们有兴趣参与 this picture . 首先,我们发送一个HTTP HEAD

    > 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 射程

    > 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
    

    有关更多信息,请参阅 Range header specification 在HTTP RFC 2616中。

        2
  •  3
  •   Xavier Combelle    15 年前

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

    注意,-c只适用于ftp

    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,含): 字节=500-600601-999 字节=500-700601-999

    Range:bytes=9500-
    

    要测试服务器是否支持它,可以测试accept范围

    接受范围:字节

    未收到资源的此标头的请求 卷入的。量程单位见第3.12节。

    不接受任何类型的范围请求的服务器

    Accept-Ranges: none
    

    建议客户不要尝试范围请求。