我想用幾種方法嘗試,然後想在這裏問這個問題..沒有辦法成功與我......我試圖解碼並從一個網站讀取數據使用gzip 我使用curl & php。當我嘗試解碼和打印結果,我得到的亂碼特殊字符,如一個長長的清單:無法使用curl解碼gzip php
JHWkdsU01EUXdWa1pXYTFOdFZsZFRiaz
VoVW14S2NGbFljRmRXYkdSWVpFZEdWRT
FYVWtoWmEyaExXVlpLTm1KR1VsWmlXR2
如果我運行下面的PHP腳本直接我有錯誤,如
PHP Warning: gzdecode(): data error in /var/www/mn.php on line 20
這裏是我當前的代碼:
<?
$data_string = '9999';
$ch = curl_init('http://example.com/getN.php&keyword=');
curl_setopt($ch, CURLOPT_USERAGENT, 'Darwin/15.0.0');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch,CURLOPT_ENCODING , 'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT,5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Accept-Encoding: gzip, deflate',
'Content-Length: ' . strlen($data_string))
);
$result = gzdecode (curl_exec($ch));
curl_close($ch);
print_r($result);
?>
我也試圖通過
a2enmod deflate
/etc/init.d/apache2 restart
使放氣模塊
,使從php.ini中的zlib的
任我嘗試測試它直接
curl -sH 'Accept-encoding: gzip' http://example.com/getN.php&keyword=9999 | gunzip -
我得到了相同的結果 這裏從網站
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 15 Oct 2015 00:41:54 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: PHP/5.4.31
X-Frame-Options: SAMEORIGIN
Content-Encoding: gzip
的信息,請幫助
它很難調試這對你自example.com的實際數據似乎沒有被gzipped – chiliNUT