0

I'm trying to create a general whereabouts locator for my chat program. It currently shows IP, Username and I'm trying to add Location. I'm attempting to use this piece of code:

var location = "";
List<string> HTML_code = new List<string>();
WebRequest request = WebRequest.Create("http://www.maxmind.com/app/locate_demo_ip?ips=" + IP);
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
  string line;
  while ((line = stream.ReadLine()) != null)
  {
    HTML_code.Add(line);
  }
}

location = (HTML_code[296].Replace("<td><font size=\"-1\">", "")).Replace("</font></td>", "");
return location;

This, however returns an exception about WebResponse:

The remote server returned an error: (403) Forbidden.(System.Net.WebResponse GetResponse())

Why am I getting this? And how can I prevent it?

SWeko
  • 30,434
  • 10
  • 71
  • 106
Daaksin
  • 834
  • 3
  • 13
  • 28

2 Answers2

2

You must have a license key in order to use this service, as written here:

All of the services take the same parameters as inputs. The only difference between them is the URI they use and the data they return. The two parameters that each service takes are the IP address to look up and your MaxMind license key.

Once you get such a key, you have to add it to the URL in addition to the IP address.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

I could not find the documentation of that particular REST API call, but it is clear from the company's website that this service is not free (at least not without a license key). This is a classic approach (you accompany each request you make to the API with your app/license key), for example both Twitter and Facebook have it.

Take a look at this link, where they give a code example of how to use their GeoIP service from C#. Also, consider taking a look at their free databases.

csima
  • 315
  • 2
  • 14