I have a url which redirects to another url.I want to be able to get the final redirected URL.My code:
public class testURLConnection
{
public st
My first idea would be setting instanceFollowRedirects
to false, or using URLConnection
instead.
In both cases, the redirect won't be executed, so you will receive a reply to your original request. Get the HTTP Status value and, if it is 3xx, get the new redirect value.
Of course there may be a chain of redirects, so probably you will want to iterate until you reach the real (status 2xx) page.