douqiao1413 2014-10-09 05:54
浏览 72
已采纳

以编码形式获取卷曲响应

I am working on curl to get Zipcode within a radius i wrote curl for this and it is working fine in Shell but when i converted it in PHP i am getting encoded response. My code is below

php code is

$headers = array(
    'Referer:http://www.freemaptools.com/find-zip-codes-inside-radius.htm',
    'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36',
    'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Encoding:gzip, deflate',
    'Accept-Language:en-US,en;q=0.5',
    'Connection:keep-alive',
    'Pragma:no-cache',
    'Cache-Control:no-cache',
    'Origin:http://www.freemaptools.com',
    'Content-Type:text/plain; charset=UTF-8'        
);


$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://www.freemaptools.com/ajax/get-all-zip-codes-inside.php?radius=50&lat=36.7017377&lng=-95.87759640000002&rn=8523');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_handle, CURLOPT_COOKIE, " __utma=126142042.1539287389.1412828292.1412828292.1412828292.1; __utmb=126142042.1.10.1412828292; __utmc=126142042; __utmz=126142042.1412828292.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmt=1");


$buffer = curl_exec($curl_handle);


curl_close($curl_handle);


echo '<pre>'; print_r($buffer);

Response is some thing like

‹Å—OoÓ@Å¿J”;aÿÍήÔVZÚmÕõÛinT¨ZDÃ>=“TY«JØÊ%ÎÁ¿Ì{3og¾ÝüørûãñäèéËè÷Ý÷ŸnǵÖãÑ×›õñXãDXé•¡çûÏÇã7&AJ?}¼[ÿ:Ÿ†2®èááçýæñ2•Í4]ÆŠ~{\߬é}õx´¾ûvûûá~óöñèíËLØÊ*#2ÓN$"*ÈÌYX4añ~Z0ÿmO020§+¼Ó38ŸÇÕõ¼(â%oKÜ‘Áä2£TÕŽ|C5/§ƒPY½R²šQ½qÝŽ:סC@x©B9ËÜÂ[ÈUÎS>Ä!¬µ\kx©ÔSÂ/vÔ«X-Aò6Ön;)íè(é6³ô„lVUê­-!äi'dXŵE>7ðÆϦe¦:LcÆ¥‹Ã©ÄA/1Wø.Te}Š¢/R·HÔÜGá¤QŠ!›"ÖÏftêO“ʽц¡ jV-M‹NˆWCÃÿC[†V«N; Mx-´dhDÇãÉ ´6{}:‹EY>Ui«zo"¶Díì()‰3±U¼LUìÍtŒI)ÜñÖJ°­·ƒ1Ï ©¥—ÜT-d›†§©(æåsS›EQ‡½©,.¼Ò[HÛÅè–zÊ!zH1GiJ;êšœ|ÚœÅ",·LËÐì_¦gHmÝ2•4-rÉW¦ÃËÔÜPM‡/hmk›è<­æ,…k ìtn“@œç¤u¹Æ"–áÌúªjؘXtÞØ®‘èsóìý€À$µ‚><ø<=Ë|i?äáN‚æNJÓq… õ7cS‘¦\Ùül2;QHk ÷’ö£sè‘uÍ6•ƒbø‰B;‚lyôœŸyWa9[ÔL؃–ˬ°hyïÐDjowÄ*Ðö5ˆ‘Û¤Ùå:Ùº³© %y$ë‹yhÒæ½½„Ež¯Tç®ØéU^¼À6)ÈZVy-<çz‹RdykZ®«UÏ:S´RJ¯eV¶ }úNˆcÂÒM¡»~9:BÚt½ŽÕ Ý㘦žîHºV¢Î»eÙ×BÇvÛÍ=ж8ê^GqžÃn¹*;ò÷‰|û|<ùÃr6…j

Please help whats wrong with my code,Your Help would be appreciated.

  • 写回答

2条回答 默认 最新

  • douliedu335997 2014-10-09 07:06
    关注

    You will get same output as in your shell script with something like that :

    $headers = array(
        'Referer:http://www.freemaptools.com/find-zip-codes-inside-radius.htm',
        'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36',
        'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language:en-US,en;q=0.5',
        'Connection:keep-alive',
        'Pragma:no-cache',
        'Cache-Control:no-cache',
        'Origin:http://www.freemaptools.com',
        'Content-Type:text/plain; charset=UTF-8'    
    );
    
    $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_URL, 'http://www.freemaptools.com/ajax/get-all-zip-codes-inside.php?radius=50&lat=36.7017377&lng=-95.87759640000002&rn=8523');
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_handle, CURLOPT_HEADER, 1); 
    curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl_handle, CURLOPT_COOKIE, " __utma=126142042.1539287389.1412828292.1412828292.1412828292.1; __utmb=126142042.1.10.1412828292; __utmc=126142042; __utmz=126142042.1412828292.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmt=1");
    
    $buffer = curl_exec($curl_handle);
    
    $header_size = curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE);
    $body = substr($buffer, $header_size);
    
    curl_close($curl_handle);
    
    $body = strtr($body,array("<"=>"&lt;","&"=>"&amp;")); // for displaying html tags
    echo($body);
    

    In your code, you didn't close your "pre" tag at then end, also,

    $curl_connection
    

    should be

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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记