1

I have a website that I want to log into from an android app and in order to submit the POST request with right information, they need some hashed values. The way that the website does it is through a javascript file. I tried tracing through it but I couldn't get the same result as the native website.

So i've decided to download their javascript file and run it within java.

My issue is that I can't figure out how to run specific methods within their file.

Here's my code so far and it's extremely bare bones.

public void hashIt(String valueForMethod1, String valueForMethod2){
    final ScriptEngineManager sem = new ScriptEngineManager();
    ScriptEngine engine = sem.getEngineByName("JavaScript");
    try {
        engine.eval(new java.io.FileReader("res/raw/theirFile.js"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
}

Any help would be much appreciated :)

Thanks

Rel
  • 11
  • 2

1 Answers1

0

You can use Invocable to invoke a method of the Javascript that has been loaded

Invocable inv = (Invocable) engine;
inv.invokeFunction("foo", "bar"); // invoke foo("bar")

See this page for a deeper introduction

Edit

As stated by Morrison Chang, apparently there is no javax.script namespace on Android, so you may check the thread he gave a link to in its comment.

Alex
  • 23,319
  • 6
  • 53
  • 50