Organizational Research By

Surprising Reserch Topic

java how to find the redirected url of a url

java how to find the redirected url of a url  using -'java,url,http-headers'

I am accessing web pages through java as follows:

URLConnection con = url.openConnection();

But in some cases, a url redirects to another url. So I want to know the url to which the previous url redirected.

Below are the header fields that I got as a response:

null-->[HTTP/1.1 200 OK]
last-modified-->[Sat, 17 Apr 2010 13:45:35 GMT]
Date-->[Sat, 17 Apr 2010 13:45:35 GMT]
Expires-->[Sat, 17 Apr 2010 14:45:35 GMT]
Set-Cookie-->[cl_def_hp=copenhagen;; path=/; expires=Sun, 17     Apr 2011 13:45:35 GMT, cl_def_lang=en;; path=/; expires=Sun, 17 Apr 2011 13:45:35 GMT]
Content-Type-->[text/html; charset=iso-8859-1;]

So at present, I am constructing the redirected url from the value of the Set-Cookie header field. In the above case, the redirected url is

Is there any standard way through which I can determine which url the particular url is going to redirect.

I know that when a url redirects to other url, the server sends an intermediate response containing a Location header field that tells the redirected url but I am not receiving that intermediate response through the url.openConnection(); method.

asked Sep 10, 2015 by Richie5498kt
0 votes

Related Hot Questions

3 Answers

0 votes
answered Sep 10, 2015 by AugustaShick
0 votes
answered Sep 10, 2015 by SeleneNason
0 votes
answered Sep 10, 2015 by Arn76Z