Say you have a URL that redirects to another (e.g., bit.ly). How do you find the real URL behind the redirect?
You can do this in Java using the HttpURLConnection class. Like this:
String url = "http://bit.ly/23414"; HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setInstanceFollowRedirects(false); con.connect(); String realURL = con.getHeaderField(3).toString();
You basically create a connection, disable auto-follow of the redirect, connect, and then query the header information to see where the redirect was pointing.