We are working on a WordPress plugin and we require an API call. We are using the api: http://www.geoplugin.net/json.gp?ip=

In this context:

     $response = wp_remote_get("http://www.geoplugin.net/json.gp?ip={$ip}",  array(
                'timeout'     => 45,
                'redirection' => 5,
                'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
            $dataArray = json_decode(wp_remote_retrieve_body($response));

However, all we get is a 403 error saying:

string(162) "
403 Forbidden

The API call worked fine using this code:


However, we are only allowed to use wp_remote_get() by WordPress.

We have been at this for a while now and we just can't get it fixed or find any solution. We have even tried to give it an user-agent argument to make it look like a browser connected but even that had no success.

Does anyone know a solution to this?

Thank you for taking your time!


An example expected return:

  "geoplugin_credit":"Some of the returned data includes GeoLite data created by MaxMind, available from <a href='http:\/\/www.maxmind.com'>http:\/\/www.maxmind.com<\/a>.",
  "geoplugin_countryName":"United States",
  "geoplugin_continentName":"North America",

Why do you have curly brackets in there?

Maybe sanitize/process the query string with htmlspecialchars() first. The error is complaining about non-standard characters...which is what your curly brackets are doing.

Build the query string with the $ip value, convert with htmlspecialchars(), then add the URL to the query string. Pass that variable to the wp_remote_get() function.

  • It's just out of habit and good practice since it's required in cases of objects or arrays. But even a hard-coded string like the one I gave in the answer http://www.geoplugin.net/json.gp?ip= for example gives the same 403 forbidden error. :( – Rick Standaert Jun 29 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.