How to Find the Real URL Behind a Redirect in Java
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 […]