分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

curl解压gzip页面gzcompress内容

发布时间:2023-09-06 01:25责任编辑:苏小强关键词:url
$headers = array(
???????//"Content-type:application/json;charset=‘utf-8‘",
???????"Cache-Control:no-cache",
???????"Pragma:no-cache",
???????//"accept-charset:utf-8",
???????"Accept-Encoding:gzip",
???????"User-Agent:Dalvik/2.1.0 (Linux; U; Android 5.1.1;Build/LMY47V)",
???????"Host:www.domain.cn",
???????//‘Transfer-Encoding:chunked‘, 压缩不能用这项
???????//"Content-Type:application/x-www-form-urlencoded",
???????//"Connection:Keep-Alive",
???);

/*
* 可写文件
$sourceFile="tmp.txt";
$fp = fopen($sourceFile, "w");
*/

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_ENCODING, ‘gzip‘); //curl解压gzip页面内容
curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_HTTPGET, true);
//curl_setopt($curl, CURLOPT_FILE, $fp);
$data = curl_exec($curl);
curl_close($curl);

//file_put_contents(‘tmpdata.txt‘,$data);
echo bin2hex($data); ???//可查看下16进制
$ret = gzuncompress($data);

print_r(json_decode($ret,true)

curl解压gzip页面gzcompress内容

原文地址:http://www.cnblogs.com/jking10/p/7852894.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved