tags:

views:

36

answers:

2

I wanna know that how we can identify whether a page is redirecting to some other web page or not?

I'm using URLConnection class of java. One way that i know is, to check the headerfield 'Location' of the connection established.

But i'm not getting the solution :-(

Plz assist.

+1  A: 

Start using HttpClient and stop worrying about redirects.

Read here for more details.

kgiannakakis
I've used HttpClient but it's not working.landing me to an error 'Connection to http://home.com refused'I wanna check whether the page is redirecting to some other page or not.
Ritz
I used that 'Location' header too.Its value is NULL, showing that the page is not redirecting..
Ritz
+1  A: 

Java HttpURLConnection follow redirects automatically, unless you call

HttpURLConnection.setFollowRedirects(false);

try calling it before you open the url (you only need to do it once, it's a static function).

I am not sure if the Location header is respected by Java (it can be a browser only thing), but you should see an http response code of 301 or 302 (if I am not mistaken) which indicates a redirect in http level.

Omry