PHP卷曲的谷歌API不工作,但的file_get_contents确实
问题描述:
我试图做到这一点PHP卷曲的谷歌API不工作,但的file_get_contents确实
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=Paris%20Hilton&userip=$_SERVER[SERVER_ADDR]";
// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://google.com');
$body = curl_exec($ch);
curl_close($ch);
// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...
这是从他们的文档非常简单的,但它似乎并没有返回任何东西,但的file_get_contents完成了同样的网址只是不是https,但http
我只用http卷曲也没有运气。 任何帮助表示赞赏你们:)
答
将会有一个小问题,通过生成一个通知,它应该改变:
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=Paris%20Hilton&userip=" . $_SERVER['SERVER_ADDR'];
从
分开,你知道你肯定已经启用curl扩展?你有错误吗?
使用'curl_error($ ch)'进行调试。我敢打赌,因为你的cabundle.crt过时了。 – 2013-07-19 23:51:39