The Response object has a url () method, which should give you the final url. So you can do, for example,
String url = "http://t.co/i5dE1K4vSs"; Response response = Jsoup.connect(url).followRedirects(true).execute(); System.out.println(response.url())
If you want to get intermediate redirects, you must go after the redirect, and then check the heading for βlocationβ. For example,
String url = "http://t.co/i5dE1K4vSs"; Response response = Jsoup.connect(url).followRedirects(false).execute(); System.out.println(response.header("location"));
If it has multiple redirection, you need to recursively call the urls.
Syam s
source share