Java Utililty Methods URL Redirect

List of utility methods to do URL Redirect

Description

The list of methods to do URL Redirect are organized into topic(s).

Method

StringgetRedirectedUrl(String url)
get Redirected Url
HttpURLConnection connection;
String finalUrl = url;
do {
    connection = (HttpURLConnection) new URL(finalUrl).openConnection();
    connection.setInstanceFollowRedirects(false);
    connection.setUseCaches(false);
    connection.setRequestMethod("GET");
    connection.connect();
...
URLgetRedirectUrl(final URL url)
Sends a request to the given URL and checks, if it contains a redirect.
try {
    URL internalUrl = url;
    URL previousUrl = null;
    int redirectCtr = 0;
    while (internalUrl != null && redirectCtr < MAX_REDIRECT_COUNT) {
        redirectCtr++;
        final HttpURLConnection urlConn = (HttpURLConnection) internalUrl.openConnection();
        urlConn.setAllowUserInteraction(false);
...