Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps PHP CURL issue "Your client has issued a malformed or illegal request. That’s all we know."

I have a function which returns the coordinates of an address using CURL and the Google Maps API.

The code is as follows:

function get_coordinates($address_string) {

    $address = urlencode($address_string);
    $url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $address . "&key=" . $api_key;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
    $response_a = json_decode($response);
    $status = $response_a->status;

    return $response;

}

The code works fine for me and 99% of the web servers I use it on - but for around 1% of servers Google returns the error message:

Your client has issued a malformed or illegal request. That’s all we know.

I've checked and the Google API key is correct, PHP CURL is enabled and the PHP version matches PHP versions it is working on.

Can anyone think of any other things which could be causing Google to return this message?

like image 202
The Bobster Avatar asked Nov 14 '17 06:11

The Bobster


People also ask

How do you fix your client has issued a malformed or illegal request that's all we know?

What are the major ways to Fix “Your client has issued a malformed or illegal request?” The major ways to Fix: Your client has issued a malformed or illegal request are to verify the File size, Recheck URL format, disable extensions, use incognito mode, delete DNS cache, and delete browser cache and cookies.

What does this mean 400 that's an error your client has issued a malformed or illegal request that's all we know?

The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

What is a illegal request?

Illegal Request . - this means that the command sent to the device is not a valid command.


1 Answers

Its Because of your $address variable has address with white space, use str_replace and replace the white space with + sign.

It will work, i was facing same problem and fixed this way.

like image 115
rescue1155 Avatar answered Nov 14 '22 22:11

rescue1155