php - 使用'br'编码获取页面内容并通过php curl对其进行解码
问题描述
我想通过 php curl获取此页面的内容:
我的卷曲样本:
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;
}
回复:
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)
响应编码是br
,响应内容是false
我知道使用gzip
或deflate
作为编码会给我一个内容。但是,我想到的内容仅通过br
编码显示。
我在此页面上阅读了Curl V7.57.0
支持该Brotli Compression
功能的内容。我目前已7.59.0
安装版本,但 Curl 在接收br encoding
.
现在我想知道如何获取带有br
编码的页面内容并通过 php curl 解压缩它?
解决方案
如果您使用 cloudflare,那么您可以尝试从 cloudflare 禁用 brotli 扩展。
推荐阅读
- angular - 选项值更改时从选择中获取值
- android - 为什么 FirebaseFirestore 在删除不存在的文件时不抛出异常?
- android - 在带有 dexguard 的 Android 应用程序的发布版本中未应用书法字体
- asp.net-mvc - MVC 的自定义 URL
- java - OpenHFT Chronicle Queue 写入字段标记为瞬态
- django-rest-framework - 无法使用 django rest swagger 运行 Django-rest-framework 应用程序
- powershell - 如何使用 Export-Excel 将未知数量的值写入一列?
- ios - 连接套接字后,GCDAsyncSocket 不会写入
- swift - 如何使用 SwiftUI 为支持多个场景的应用程序隐藏 .phonePad 类型的键盘?
- python-3.x - python - 如何循环选择菜单直到输入在范围内