通过'br'编码获取页面内容并通过php curl解码它

I want to get content of this page by php curl:

my curl sample:

function curll($url,$headers=null){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);


    if ($headers){

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }

    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0');
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $response = curl_exec($ch);

    $res['headerout'] = curl_getinfo($ch,CURLINFO_HEADER_OUT);
    $res['rescode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($response === false) {
        $res['content'] = $response;
        $res['error'] = array(curl_errno($ch),curl_error($ch));
        return $res;
    }

    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $res['headerin'] = substr($response, 0, $header_size);
    $res['content'] = substr($response, $header_size);

    return $res;

}

response:

array (size=4)
  'headerout' => string 'GET /wallets HTTP/1.1
Host: www.cryptocompare.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: br
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Upgrade-Insecure-Requests: 1

' (length=327)
  'rescode' => string '200' (length=3)
  'content' => boolean false
  'error' => 
    array (size=2)
      0 => int 23
      1 => string 'Unrecognized content encoding type. libcurl understands deflate, gzip content encodings.' (length=88)

response encoding is br and response content is false

I am aware that using gzip or deflate as encoding would get me a content. However, the content that I have in mind is only shown by br encoding.

I read on this page that Curl V7.57.0 supports the Brotli Compression Capability. I currently have version 7.59.0 installed, but Curl encounters an error as it recieves content in br encoding.

now I want to know how can I get content of a page with br encoding and uncompress it by php curl ?

doulao1934
doulao1934 我自己,通过将用户代理字符串设置为没有Brotli支持的值,我能够让上游服务器向我发送没有brotli编码的内容。检查caniuse.com/#feat=brotli以找出哪些没有(提示:我将其设置为Chrome49-现有的UA列于:myip.ms/view/comp_browsers/4301/Google_Chrome_49.html?
大约 2 年之前 回复
drake900918
drake900918 有一个Brotli扩展可用于PHP:github.com/kjdev/php-ext-brotli-也许这可以帮助您解决问题?
大约 2 年之前 回复
douyong8801
douyong8801 您提到的页面讨论了Curl本身,而不是PHP中的Curl实现。此外,在您的代码中,您设置curl_setopt($ch,CURLOPT_ENCODING,'');根据文档php.net/manual/en/function.curl-setopt.php的意思是:“包含所有支持的编码类型的头文件被发送”-它表示:“identity”,“deflate”和“gzip””。请注意,此处未提及“br”,因此不支持Brotlide-/compression。但也许这已经过时了?找出答案的方法是:检查PHP安装使用的卷曲版本:php.net/manual/en/function.curl-version.php
大约 2 年之前 回复
duanmu8911
duanmu8911 对不起,但我更新了问题
2 年多之前 回复
dongliao8069
dongliao8069 如果回复是假的,你在$res['error']得到了什么?
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐