G
G
Gregory2016-04-27 12:36:30
Java
Gregory, 2016-04-27 12:36:30

How to get final url after all redirects, including JS redirects?

Good afternoon.
There is a function with which I get the final URL after redirects on the server:

public static String getFinalURL(String url) throws IOException {
    HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
    con.setInstanceFollowRedirects(false);
    con.connect();
    con.getInputStream();

    if (con.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM || con.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
        String redirectUrl = con.getHeaderField("Location");
        return getFinalURL(redirectUrl);
    }
    return url;
}

Is it possible to make the function recognize redirects written in JS?
Surely through HttpURLConnection will not work, but perhaps there are other means?
The android webview is not suitable.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question