任何人都不会知道如何解的内容gzip文件,我有带卷?

例如: http://torcache.com/torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent

回答

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 09 Jun 2010 01:11:26 GMT
Content-Type: application/x-bittorrent
Content-Length: 52712
Last-Modified: Tue, 08 Jun 2010 15:09:58 GMT
Connection: keep-alive
Expires: Fri, 09 Jul 2010 01:11:26 GMT
Cache-Control: max-age=2592000
Content-Encoding: gzip
Accept-Ranges: bytes

然后压缩gzip,

我试图gzdecode但不工作,gzeflate以及不他们只是没有得到任何答复,内容的文件是不超过2k

有帮助吗?

解决方案

使用 gzdecode

<?php
    $c = file_get_contents("http://torcache.com/" .
        "torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent");
    echo gzdecode($c);

给出

d8:announce42:http://tracker.openbittorrent.com/announce13:announce-listll42
...

其他提示

只要告诉卷曲到响应自动解码每当它是gzip压缩

curl_setopt($ch,CURLOPT_ENCODING, '');

libcurl的报价一个功能,使得它自动解压缩的内容(如果与ZLIB构建)。

请参阅所述CURLOPT_ENCODING选项: http://curl.haxx.se/libcurl /c/curl_easy_setopt.html#CURLOPTENCODING

你尝试设置首标指出您接受gzip编码如下:

curl_setopt($rCurl, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip,deflate'));

通过一个 zlib的流封包:

file_get_contents("compress.zlib://http://torcache.com/" .
    "torrent/63ABC1435AA5CD48DCD866C6F7D5E80766034391.torrent");

你有没有试过 gzuncompressgzinflate?

gzdeflate 压缩, 相反的你想要什么。说实话,我不可能找出如何 gzdecode 不同于正常的解压.

还有的卷曲的选择 CURLOPT_ENCODING:

内容"Accept-Encoding:"头。 这使得解码的反应。 支持编码是"身份","deflate",并"gzip".如果一个空string,"",设,标题包含所有支持类型的编码发送。

这似乎意味着它会自动地解答,但是我还没有进行测试。

您可以用gzinflate做到这一点(假装$头包含了所有的HTTP标头和$缓冲区包含数据):

if (isset($headers['Content-Encoding']) && ($headers['Content-Encoding'] === 'gzip' || $headers['Content-Encoding'] === 'deflate'))
    {
        if ($headers['Content-Encoding'] === 'gzip')
        {
            $buffer = substr($buffer, 10);
        }
        $contents = @gzinflate($buffer);
        if ($contents === false)
        {
            return false;
        }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top