1

我尝试使用 Range-header 在 Greasemonkey 脚本中发送请求。请求的站点有点长,我知道我真正需要哪些部分,所以我想,与其请求整个站点下载,不如请求必要的 500 字节来加快速度。

但是,Range: bytes=0-500总是给我完整的网站。我也试过Content-Range: bytes=0-500了,它不起作用,并且Content-Length:500由于安全问题不允许再设置。

那么,有谁知道,为什么会这样?我正在使用 Greasemonkey 脚本:

 GM_xmlhttpRequest({
    method: 'GET',
    url: "http://colonel-strawberry.deviantart.com/",
     headers: {"Range": "bytes=0-500"}, 
    onload: function (responseDetails) {
      console.log(responseDetails);
    },
    onerror: function(responseDetails) {
      console.log("err:"+responseDetails);
    }
});

带有响应头:

Date: Mon, 05 Nov 2012 17:11:42 GMT
Content-Encoding: gzip
Transfer-Encoding: chunked
P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR CURa OUR STP"
Connection: Keep-Alive
Server: Apache
Vary: Accept-Encoding
Content-Type: text/html
Cache-Control: private
Keep-Alive: timeout=45
4

1 回答 1

5

主机colonel-strawberry.deviantart.com似乎不支持字节范围的请求。

您需要从支持它们的服务器请求数据。

(我通过比较首先curl -H "Range: bytes=50-60" $foo在哪里,然后在我控制的服务器上的 URI 进行测试)。$foohttp://colonel-strawberry.deviantart.com

注意HTTP 规范

服务器可以忽略 Range 标头。

于 2012-11-05T17:23:51.327 回答