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 › problem  with loadStrings and URLs
Page Index Toggle Pages: 1
problem  with loadStrings and URLs (Read 958 times)
problem  with loadStrings and URLs
Aug 16th, 2007, 12:22am
 
dear all,

I am sure this is straightforward and simple!

I am trying to load text from a URL using the loadStrings command - so far so straightforward. The code below works perfectly fine locally but once uploaded no text is being loaded in. I can pull the text in from a .txt. file but need to pull it from a URL.

Any thoughts? (I have loaded the text both this way and through a buffer but no luck!)

thanks, Aidan

--
// Pull data from a URL and make into a string
//
void setup()
{
 size(200, 200);  // Size should be the first statement
 stroke(255);     // Set line drawing color to white
 background(80); // bkgd to grey
 noLoop();
 PFont AndaleMono;
 AndaleMono = loadFont("AndaleMono-12.vlw");
 textFont(AndaleMono, 12);
}
//
void draw()
{
textAidan();
}
//
void textAidan()
{
 String lines[] = loadStrings("http://www.yahoo.com"); // from web
 String onelongstring = ""; //set variable to empty
 for (int i = 0; i < lines.length; i++) { // count number of lines
 onelongstring = onelongstring + lines[i] + " "; // fill variable with lines
}
//
println(onelongstring);
text(onelongstring, 10, 10, 180, 180 );
}
//
--
Re: problem  with loadStrings and URLs
Reply #1 - Aug 16th, 2007, 7:39am
 
that's due to the java security. (unsigned) applets can only get data from the server they came from.

a workaround is to pass the data thru a php file on the server .. that will allow you to access data outside of your domain.

applet, send url -> php, gets data -> applet, reads data

F
Re: problem  with loadStrings and URLs
Reply #2 - Aug 16th, 2007, 4:45pm
 
thanks for the answer fjen,

I was thinking that might be the answer and had just started to use a php solution.

Another query though (if I may), I have a PHP script working to pull the info, it is:
- working fine locally in Processing;
- working fine online;
- not working when I export it, take the applet and run it locally (the index.html file that pulls in the java file does not show the pulled data).

Any thoughts

thanks,
Aidan

----

fjen wrote on Aug 16th, 2007, 7:39am:
that's due to the java security. (unsigned) applets can only get data from the server they came from.

a workaround is to pass the data thru a php file on the server .. that will allow you to access data outside of your domain.

applet, send url -> php, gets data -> applet, reads data

F

Re: problem  with loadStrings and URLs
Reply #3 - Aug 16th, 2007, 5:19pm
 
running locally means opening the index.html in a browser or putting it on a local webserver?

both the applet and the php script need to be under the same domain. opening index.html in your browser is not gonna work since it (1) can't access the php file (remote) and (2) a local php file needs to run under a webserver to work.

F
Re: problem  with loadStrings and URLs
Reply #4 - Aug 16th, 2007, 6:53pm
 
Yes running locally I mean taking the index.html file that is created and opening it in a browser. This just brings up the html file with processing embedded in it but does not pull the info from the php file. But when I am in processing and I hit play it is able to pull from the php file.

In both scenarios the php file is uploaded to the server.

So in both instances the processing part of the files are local but one works and the other doesn't. In the big picture it is not that big of a deal as it works when uploaded, but I always like to know why. (Am guessing that it has to do with the security measures being more tight in the applet than when running through processing)

thanks,
Aidan

fjen wrote on Aug 16th, 2007, 5:19pm:
running locally means opening the index.html in a browser or putting it on a local webserver

both the applet and the php script need to be under the same domain. opening index.html in your browser is not gonna work since it (1) can't access the php file (remote) and (2) a local php file needs to run under a webserver to work.

F

Re: problem  with loadStrings and URLs
Reply #5 - Aug 16th, 2007, 7:19pm
 
When it runs within processing, it's not subject to the same restrictions as when it's running in a browser.

So when running in a browser locally, it'd only be allowed to get file from a webserver which is running on your computer, and no other, whilst within processing itself it's able to get data form anywhere.
Re: problem  with loadStrings and URLs
Reply #6 - Aug 16th, 2007, 7:25pm
 
Makes sense (for now).

Thanks Fjen and John.

Aidna
Page Index Toggle Pages: 1