wp_remote_get() returns 403 while file_get_contents() does not


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",
, , , , Rick Standaert 2 months 0 Answers 27 views 0

Leave an answer