Question

I create a server that accessing a site as if the site is accessed by a browser. Some sites that my server need to access is required the execution of javascript, my question regarding RingoJs is: can I use RingoJs runtime to execute downloaded js from the accessed site?

Was it helpful?

Solution

You can write this.

importPackage(java.net);
importPackage(java.io);
var sourceJs = "http://foo.bar.com/js/foo.js";
var url = new URL(sourceJs);

var ucon = url.openConnection();
var istream = ucon.getInputStream();
var isr = new InputStreamReader(istream, "utf-8");
var br = new BufferedReader(isr);
var line = "";
var buf = "";
while((line = br.readLine()) != null) {
     buf = buf + line + "\n";
}
eval(buf);

but, eval is very danger,if you don't know what you are doing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top