为什么旋度返回null


Why the curl return null?

我想通过php脚本获得yahoo woeid。

我可以访问urlhttp://query.yahooapis.com/v1/public/yql?q=select*来自geo.places,其中text="NewYork"&format=json,然后在浏览器中获取json文件。但当我使用旋度时,它返回null。

这就是密码。

    public function getwoeid(){
        $ch = curl_init();
        $url = 'http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text="'.$this->cityname.'"&format=json';
        //echo $url;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data=curl_exec($ch) or die($this->returnerror()); 
        curl_close($ch);
        $array = json_decode($data, true);
        return $array;
    }

当我尝试访问http://query.yahooapis.com/v1/public/yql?q=select*来自geo.places,其中text="上海"&format=json'卷曲效果良好。

我修不好。

任何建议都将不胜感激!谢谢

您只需使用PHP的file_get_contents()。空格必须由urlencode()进行编码;

$url = 'http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text="'.$this->cityname.'"&format=json';
$data = file_get_contents(urlencode($url));
$array = json_decode($data, true);

刚刚从您的代码中得到答案:

string'不支持HTTP版本

�'(长度=210)

PlaceFinder Web服务仅支持HTTP GET方法。不支持其他HTTP方法。

不能使用CURL,因为CURL作为POST方法工作。请阅读此处:http://developer.yahoo.com/geo/placefinder/guide/requests.html

您有一个打开的curl_setopt()。它如下:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ <------