php - PHP cURL 返回加密的 html 页面
问题描述
我正在尝试从 PHP 上的 cURL GET-request 获取简单的 html 代码。
url 上的默认 get-request,例如http://example.com/(不完全是这个域),返回我需要的 html 代码,但是这个域的页面上的 get-request,例如http://example.com/something返回gzip 加密数据,什么的。
我已经尝试解决此问题:
curl_setopt(ch, CURLOPT_ENCODING, ''); // returns ''
curl_setopt(ch, CURLOPT_ENCODING, 'gzip'); // returns ''
curl_setopt(ch, CURLOPT_ENCODING, 'gzip,compressed'); // returns ''
$html = gzdecode($data); // data error
顺便说一句,在检查器上,如Fiddler,此页面返回类似的奇怪符号,但只需单击一下即可修复:“单击解密”。如何使用 PHP 以编程方式解密我的数据?
解决方案
如果我理解你的话,你需要从一个 url 获取 HTML 中的内容。
请检查这个链接: Get HTML using curl in PHP
您不需要在 curl_setopt 中使用 CURLOPT_ENCODING。
编辑
我试过这个并且它有效:
<?php
function get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html_content = get_data('https://stackoverflow.com/questions/61548866/php-curl-returns-encrypted-html-page/61549219?noredirect=1#comment108875034_61549219');
echo "You are getting HTML code from an url <br>".$html_content;
?>
谢谢,希望对你有帮助。
推荐阅读
- flutter - 用户完成 Web 表单后如何自动返回 Flutter 应用
- openebs - 无法在 RancherOS 上配置 OpenEBS 卷
- javascript - 在 Safari 中滚动时导航闪烁
- javascript - 如何制作字符串回文?
- c# - 如何决定 .net 框架版本来创建库
- python - 图像配准/对齐和转换如何在像素级别上工作?
- mysql - ERPNext OperationalError (2003, "Can't connect to MySQL server on u'localhost' ([Errno 22] Invalid argument)")
- html - 如何使文本框中的文本影响代码?
- c# - 为什么单元测试仍然没有像调试它移动到数据访问层时那样被嘲笑
- dart - 为颤振更新 dart sdk