简体   繁体   English

没有收到来自php google geocode rest api请求的响应

[英]getting no response from php google geocode rest api request

I'm getting no response and no errors from this php code. 我没有得到任何回应,也没有从此php代码中得到任何错误。 Does anyone know what I'm doing wrong, please? 请问有人知道我在做什么错吗? It seems straightforward: 看起来很简单:

php: 的PHP:

$details_url = "https://maps.googleapis.com/maps/api/geocode/json?address=436+Grant+Street+Pittsburgh&sensor=false&key=mykey";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   $response = curl_exec($ch);
   print_r($response);

You never bothered to tell curl about your url. 您从不费心告诉curl有关您的网址。 You should have 你应该有

$ch = curl_init($details_url);
                ^^^^^^^^^^^^

or 要么

curl_setopt($ch, CURLOPT_URL, $details_url);

And note that print_r is not a good debug tool. 请注意,print_r不是一个好的调试工具。 You probably got a boolean false from curl_exec, which print_r won't display at all: 您可能从curl_exec中得到了一个布尔假,而print_r根本不会显示:

php > $x = false;
php > print_r($x);
php > var_dump($x);
bool(false)

A better option would be 更好的选择是

$response = curl_exec($ch);
if ($response === false) {
    die(curl_error($ch));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM