dongtuoji5396 2013-02-12 20:08
浏览 85
已采纳

试图用curl和输出读取部分HTML文件很奇怪

set_time_limit(0);
$ch = curl_init('http://www.tibia.com/community/?subtopic=highscores&world=Antica');
curl_setopt($ch, CURLOPT_RANGE, '0-999');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
echo $data = curl_exec($ch);//get curl response
curl_close($ch);

And the example output is (it is slightly different every time I hit refresh button):
‹í]kSã8ºþNÕü­OÍÕr™&™‚ ³ÜÒ3{æ¥8J¢Æ±2¾é=ûßÏ«‹Û±BãYÜåž,[¥÷òHz%[ÎÁØ›XÖÆàˆÐG=‹tz´O1ª S‡té[ZxF tm[Ô&è–YÝÀ%jÐ'¿½?¿<ütrÇË‹_X_BD1‡Ýîõç«^¤œàŠ(Èå%ÓwH¤$lšÌ·½°¨Ñý)s&W¼‰­Ç¯Rb ¢‰Ð{dЪ zp×½=¿é¡ÞÿÞœ,úµ³vð·JU«0D@EÔ²ˆ³æ¯G'„A{Û0Ì1tjä´ÜØ4þŽšµZmóãÚзMÞÆQ4{íßà=:DSì@³ß ò2Ý-‹Ø#oŒ:¨± ‰þ-üË1}‡=¹Äéͦ¨ÝF%F‹ºßb²#i˜éO¢W> à]û\b ·<6]~ßÿÿ?k v¥&¨JuÖÖÞ®PB)¶èWm ƒÁþ~}¿ÖÜÛö÷wš ÒØ®Õ04IØÜ!õdS€1½ªuHö

The page is displayed correctly when I comment out CURLOPT_RANGE

EDIT: I added curl_setopt($ch, CURLOPT_ENCODING, "gzip"); The output seems to be okay, but only when the range starts with 0. If the range is for example 2000-3000, it outputs completely nothing.

EDIT 2: The error message is: "Error while processing content unencoding: invalid distance too far back"

  • 写回答

2条回答 默认 最新

  • douwengzao5790 2013-02-12 20:26
    关注

    I've never used CURLOPT_RANGE. Is there a reason you need to use this?

    The reason gzip only works when you start from 0 is there is information there that it needs to unzip the content. If you must use Range then you should capture the data for each range and combine it and then un-gzip that.

    EDIT:

    You mention in some comments that you use Range to get some of the data to save bandwidth. I checked the page using Firebug and it's < 10kb. With all the images it's almost 500k. You are already saving quite a bit and unless you're using dial-up internet 10kb it's nothing. Don't worry about using Range and combining the chunks, just let cURL handle the gzip.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想用@vueuse 把项目动态改成深色主题,localStorge里面的vueuse-color-scheme一开始就给我改成了dark,不知道什么原因(相关搜索:背景颜色)
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥20 白日门传奇少一个启动区服和启动服务器的快捷键,东西都是全的 , 他们说套一个出来就行了 但我就是弄不好,谁看看,
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题