How can I get the "final location" (a.k.a. landing-page) of the following URL:
My code (below) takes this string as input.
The output should be something like 'http://weeklyad.target.com', but instead, I just get the same URL.
No need to mention, I am unable to solve this specific case, but I still need a general solution.
Here is my simple Java code, using HttpURLConnection (where String ref is the input):
HttpURLConnection con = (HttpURLConnection)new URL(ref).openConnection();
con.setInstanceFollowRedirects(true);
con.setRequestProperty("User-Agent","");
if (con.getResponseCode()/100 == 3)
{
String target = con.getHeaderField("Location");
if (target != null)
return target;
}
return con.getURL().toString();
Does anybody have any idea what am I doing wrong?