我正在尝试这样做
$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返回相同url不是HTTPS,而是HTTP
我也尝试过只使用HTTP的curl,但没有运气。任何帮助都是感激的家伙:)
会有一个小问题和一个通知,应该改变:
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=Paris%20Hilton&userip=" . $_SERVER['SERVER_ADDR'];
除此之外,你知道你肯定启用了Curl扩展吗?你得到一个错误吗?