title: Google Geocoding service returns Error 400 Bad Request
body: <p>I've been trying to get a json response from google's geocoding service. I'm using PHP. I was trying with fopen, then I read in another stackoverflow question that I should use file_get_contents, but didn't worked too. Then I keep searching and found someone in another forum who said I would a better solution if I use CURL so I changed my code and is not working. In all cases I received an "Error 400: Bad Request. Your client has issued a malformed or illegal request."</p>
  
  <p>My code is this:</p>
  
  <pre><code>$jsonUrl = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $cityName . "&amp;sensor=false";
  
      $geocurl = curl_init();
      curl_setopt($geocurl, CURLOPT_URL, $jsonUrl);
      curl_setopt($geocurl, CURLOPT_HEADER,0); //Change this to a 1 to return headers
      curl_setopt($geocurl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
      curl_setopt($geocurl, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($geocurl, CURLOPT_RETURNTRANSFER, 1);
  
      $geofile = curl_exec($geocurl);
  </code></pre>
  
  <p>Then I print the content and got the error message.</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you very much.</p>