Guad / GTACoop

An online co-op modification for GTA5
GNU General Public License v3.0
81 stars 71 forks source link

Need help with geolocation API #77

Open Bluscream opened 7 years ago

Bluscream commented 7 years ago

I'm probably stupid but i can't seem to get this to work:

            string response = String.Empty;
            try
            {
                using (var webClient = new System.Net.WebClient())
                {
                    response = webClient.DownloadString("http://ip-api.com/json/"+player.NetConnection.RemoteEndPoint.Address);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not contact IP API.");
            }
            if (!string.IsNullOrWhiteSpace(response)) {
                IPInfo dejson = JsonConvert.DeserializeObject<IPInfo>(response);
                if (dejson.list != null)
                {
                    if (dejson.status.Equals("success"))
                    {
                        string country = dejson.countryCode;
                        Console.WriteLine("Country Code: "+country);
                    }else
                    {
                        Console.WriteLine("Could not query IP infos from API.");
                    }
                }

            }

It always throws a System.NullReferenceException: Object reference not set to an instance of an object. somewhere around that code.