Site icon Hip-Hop Website Design and Development

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=8.8.8.8

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));
            var_dump($response);

However, all we get is a 403 error saying:

string(162) "
403 Forbidden
nginx 
"

The API call worked fine using this code:

file_get_contents("http://www.geoplugin.net/json.gp?ip={$ip}")

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!

Edit:

An example expected return:

{
  "geoplugin_request":"8.8.8.8",
  "geoplugin_status":206,
  "geoplugin_delay":"2ms",
  "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_city":"",
  "geoplugin_region":"",
  "geoplugin_regionCode":"",
  "geoplugin_regionName":"",
  "geoplugin_areaCode":"",
  "geoplugin_dmaCode":"",
  "geoplugin_countryCode":"US",
  "geoplugin_countryName":"United States",
  "geoplugin_inEU":0,
  "geoplugin_euVATrate":false,
  "geoplugin_continentCode":"NA",
  "geoplugin_continentName":"North America",
  "geoplugin_latitude":"37.751",
  "geoplugin_longitude":"-97.822",
  "geoplugin_locationAccuracyRadius":"1000",
  "geoplugin_timezone":"",
  "geoplugin_currencyCode":"USD",
  "geoplugin_currencySymbol":"$",
  "geoplugin_currencySymbol_UTF8":"$",
  "geoplugin_currencyConverter":1
}