We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Get URL data and return vars.
Page Index Toggle Pages: 1
Get URL data and return vars. (Read 995 times)
Get URL data and return vars.
Apr 19th, 2010, 2:49am
 
Hi all!

Im looking for a way to read this URL http://api.hostip.info/get_html.php?position=true&ip=12.215.42.19
And return the value's as a var.
(12.215.42.19 is also a given var.)

Any thoughts?
Re: Get URL data and return vars.
Reply #1 - Apr 19th, 2010, 3:09am
 
You'll have to parse the data yourself, but you can get it all into a String by:

Code:
String ip="12.215.42.19";
String[] data=loadStrings("http://api.hostip.info/get_html.php?position=true&ip="+ip);
//will give an array of strings, one per line e.g.
/*
data[0]="Country: UNITED STATES (US)"
data[1]="City: Sugar Grove, IL"
data[2]=""
data[3]="Latitude: 41.7696"
data[4]="Longitude: -88.4588"
data[5]="IP: 12.215.42.19"
*/
Re: Get URL data and return vars.
Reply #2 - Apr 19th, 2010, 3:33am
 
Holy **** thats sweet!

thank you so much!!
I saw a java script to do the same but that was a damn long code ^^

One more thing, how do I split this string on data[0] at ":" (semicolon)
Re: Get URL data and return vars.
Reply #3 - Apr 19th, 2010, 5:50am
 
: is a colon, not a semicolon.
And you split strings by using... split()!
Page Index Toggle Pages: 1