[ANDROID]How to get HTML source from a URL(using WEBAPI for uTorrent)

101 views Asked by At

I need to get a simple string out of the HTML code in a url.

FwyKvZJSZMLdgAlEuMvw7v_s9VhasprI-47KeavMegGJlvAC5ZLwng5gEFgAAAAA .

This is how it looks like. All I need is the string from the start.

This is the URL request I use to reach the code.

http://username:password@IP:8080/gui/token.html

The answers I found were either way too complicated or straight up didnt work (HTTPClient is now deprecated :( ).

This is what I have, but sadly it always returns java.io.FileNotFoundException: http://www.google.com and it does that on every website.

This is the code for it:

try {
    System.out.println("TEST");
    con = (HttpURLConnection) new URL("http://username:password@IP:8080/gui/token.html").openConnection();
    con.setRequestMethod("GET");
    con.setDoOutput(true);
    con.setDoInput(true);
    System.out.println(con.getOutputStream().toString());
    InputStream response = con.getInputStream();
    System.out.println("RMessage" + con.getResponseMessage());
    con.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) ");
    con.setRequestProperty("Accept","*/*");
    BufferedReader reader = new BufferedReader(new InputStreamReader(response));
    for (String line; (line = reader.readLine()) != null; ) {
        System.out.println(line + "NEKAJ SE JE ZGODILO V PRIDOBITVI");
    }
    reader.close();

} catch (MalformedURLException e1) {
    e1.printStackTrace();
} catch (ProtocolException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}

}

The link works alright in my Chrome App on my device.

Getting the source of something like Facebook.com or Google works alright too. I'm super confused.

EDIT: Printed the stacktrace: 10-26 11:45:52.816 3341-3721/com.example.davidvuckovic7.utorrentclient W/System.err: java.io.FileNotFoundException:

To avoid posting a separate thread for it, is there a way to customize URL's? To get user input username and password or user input IP?

1

There are 1 answers

0
Nephilim On

Apparently I need to fix my cookies. Because browsers handle cookies automatically and my app doesn't, it causes issues. Tokens and cookies are apparently connected.

Now on to the next problem,