dousi6405 2013-09-27 20:57
浏览 43

服务器没有给出卷曲代码的任何响应

i am new to curl and making a program which will search using yahoo search engine here is my code:-

<?php
        $handle=curl_init();
        curl_setopt($handle,CURLOPT_URL,"http://search.yahooapis.com/ImageSearchServ/V1/imageSearch");
        curl_setopt($handle,CURLOPT_POST,true);
        //curl_setopt($handle,CURLOPT_POSTFEILDS,"appid=$appID&query='water bear&results=5'");
        curl_setopt($handle,CURLOPT_RETURNTRANSFER,true);
        $response=curl_exec($handle);
        curl_close($handle);
        print_r($response);
    ?>

when i run this code the browser does not show any error message or any response it just bzy in requesting to the server like an infinite loop. can you please help me

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dragonmeng2002 2013-09-27 21:43
    关注

    There are three problems with your code:

    • You're passing a string to post via curl. This is bad. You should prepare carefully the structured data to send.

    Example:

     $data = array('appid'=>'12345',
                   'query'=>'water bear',
                   'results'=>5);
     $data = http_build_query($data, '', '&amp;'); // use native helper methods
     curl_setopt($handle,CURLOPT_POSTFIELDS,$data);
    
    • There is a typo in your code: CURLOPT_POST(FEI)LDS should be CURLOPT_POST(FIE)LDS.

    • Yahoo's restful search api url's changing in favor of the BOSS api. Your request uri should look something like this:

    http://yboss.yahooapis.com/ysearch/{service,*}?q={keywords}
    

    From the documentation:

    BOSS API is an updated service that provides RESTful access to Web, Image, News, Spelling, and Blog search results with a simple pricing scheme based on usage. The service also provides qualifying developer's access to Yahoo! Search Advertising.

    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本