Solved

API Location, separating out information

Posted on 2016-07-24
10
43 Views
Last Modified: 2016-07-26
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!
0
Comment
Question by:Graeme
  • 5
  • 5
10 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
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
 

Author Comment

by:Graeme
Comment Utility
Hi Ryan, just used your code (replaced ACCESSKEY) - not showing any values thou....

GetTextFromUrl =

Location =
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
hi similarly, can you do a response out for oXMLHTTPLoc.responseText and post it here?
0
 

Author Comment

by:Graeme
Comment Utility
Response.Write(oXMLHTTPLoc.responseText)

Open in new window


403 Forbidden

nginx

No idea what nginx is, possibly part of the API
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Graeme
Comment Utility
That works fine:

OK;;203.161.69.136;AU;Australia
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
Comment Utility
what if you change:

oXMLHTTPLoc.Open "POST",LocationAPI, False
to:
oXMLHTTPLoc.Open "GET",LocationAPI, False
?
0
 

Author Closing Comment

by:Graeme
Comment Utility
Bingo! works a dream! thanks mate! :)
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
cool man, this seems easier than your another question but at least you got one more issue resolved! cheers
0
 

Author Comment

by:Graeme
Comment Utility
haha yeah totally! definately some curly questions! :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now