My first idea would be to set instanceFollowRedirects to false or instead of URLConnection .
In both cases, the redirect will fail, so you will receive a response to your initial request. Get the HTTP status value and, if it is 3xx, get the new redirect value.
Of course, there might be a chain of redirects, so you might want to repeat the iteration until you reach a real (2xx status) page.
SJuan76
source share