python偏移量没看懂_python – 从服务器读取一些偏移量的文件

您应该在请求中使用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

接下来,我们发送一个带有Range标头的GET请求,询问图片的前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

有关详细信息,请参阅HTTP RFC 2616中的Range header specification.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值