我试图使用PHP和卷曲获得来自谷歌Places API的数据,但卷曲是给我的错误“无法连接到主机”。如果我将Google地方信息请求网址粘贴到浏览器中,则可以正常使用。 file_get_contents也没有工作。这里是我的代码:无法连接到主机错误与谷歌Places API的和PHP /卷曲
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString);
$result = curl_exec ($ch);
if (curl_errno($ch)) {
return curl_error($ch);
} else {
curl_close($ch);
}
return $result;
我要求的网址是https://maps.googleapis.com/maps/api/place/search/json?key=xxx&location=27.916766641249062,-82.08984375&radius=50000&sensor=true&types=bar%7Cnight_club。为了安全起见,我删除了我的API密钥。
我不是一个PHP的家伙,自动卷曲URL编码请求? – 2012-01-05 16:09:19
我试着URL编码请求,没有任何改变 – user1132322 2012-01-07 22:11:01