API Location, separating out information

Hi All, I have recently learnt a little about APIs and how awesome they are (using a currency API)

Now I would like to use a GeoLocation API - IPInfoDB

API Link: http://api.ipinfodb.com/v3/ip-country/?key=ACCESSKEY&ip=IPADDRESS

API Output
OK;;74.125.45.100;US;United States

Open in new window


This is what I got so far (copying from the Currency API):
Dim oXMLHTTPLoc

Set oXMLHTTPLoc=CreateObject("MSXML2.ServerXMLHTTP")

LocationAPI="http://api.ipinfodb.com/v3/ip-country/?key=ACCESSKEY&ip="&Request.ServerVariables("REMOTE_ADDR")

oXMLHTTPLoc.Open "POST",LocationAPI, False
oXMLHTTPLoc.Send

If oXMLHTTPLoc.Status = 200 Then
    GetTextFromUrl3 = oXMLHTTPLoc.responseText
    Arr1 = Split(GetTextFromUrl3, "OK")
    Arr2 = Split(Arr1(1), ";")
    Arr3 = Split(Arr2(1), " ")
    CountryLoc=Arr3(0)
End If
  
Response.Write("GetTextFromUrl = "&GetTextFromUrl3&"<br><br>Location = "&CountryLoc)

Open in new window


The End result that all I would like is: the 2 letter country Code
eg:
AU
US
GB
etc

Thanks in advance!
Graemewebber4technologiesAsked:
Who is Participating?
 
Ryan ChongConnect With a Mentor Commented:
hi you can try customize this:
<%


Dim oXMLHTTPLoc

Set oXMLHTTPLoc=CreateObject("MSXML2.ServerXMLHTTP")

LocationAPI="http://api.ipinfodb.com/v3/ip-country/?key=ACCESSKEY&ip="&Request.ServerVariables("REMOTE_ADDR")

oXMLHTTPLoc.Open "POST",LocationAPI, False
oXMLHTTPLoc.Send

If oXMLHTTPLoc.Status = 200 Then
    GetTextFromUrl3 = oXMLHTTPLoc.responseText
    
    if ucase(left(GetTextFromUrl3, 2)) = "OK" then
        CountryLoc=Split(GetTextFromUrl3,";")(3)
    end if
End If
  
Response.Write("GetTextFromUrl = "&GetTextFromUrl3&"<br><br>Location = "&CountryLoc)


%>

Open in new window

0
 
Graemewebber4technologiesAuthor Commented:
Hi Ryan, just used your code (replaced ACCESSKEY) - not showing any values thou....

GetTextFromUrl =

Location =
0
 
Ryan ChongCommented:
hi similarly, can you do a response out for oXMLHTTPLoc.responseText and post it here?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Graemewebber4technologiesAuthor Commented:
Response.Write(oXMLHTTPLoc.responseText)

Open in new window


403 Forbidden

nginx

No idea what nginx is, possibly part of the API
0
 
Ryan ChongCommented:
it means the request to the API seems invalid.

can you see what's the value of LocationAPI, and copy and paste it into your browser, see if got any error there?
0
 
Graemewebber4technologiesAuthor Commented:
That works fine:

OK;;203.161.69.136;AU;Australia
0
 
Ryan ChongConnect With a Mentor Commented:
what if you change:

oXMLHTTPLoc.Open "POST",LocationAPI, False
to:
oXMLHTTPLoc.Open "GET",LocationAPI, False
?
0
 
Graemewebber4technologiesAuthor Commented:
Bingo! works a dream! thanks mate! :)
0
 
Ryan ChongCommented:
cool man, this seems easier than your another question but at least you got one more issue resolved! cheers
0
 
Graemewebber4technologiesAuthor Commented:
haha yeah totally! definately some curly questions! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.