I know that for the following redirected URLs in JAVA, the java.net.httpURLConnection class may be useful. Therefore, for this purpose, the following method is implemented:
public static String getRedirectedUrl(String url) throws IOException {
HttpURLConnection con = (HttpURLConnection) (new URL(url).openConnection());
con.setConnectTimeout(1000);
con.setReadTimeout(1000);
con.setRequestProperty("User-Agent", "Googlebot");
con.setInstanceFollowRedirects(false);
con.connect();
String headerField = con.getHeaderField("Location");
return headerField == null ? url : headerField;
}
My problem is that this method cannot track the redirected URLs for some URLs, such as the following URL. However, it is great for most redirected URLs.
http://ubuntuforums.org/search.php?do=getnew&contenttype=vBForum_Post
source
share