Sometimes my URL will redirect to a new page, so I want to get the URL of the new page.

Here is my code:

URL url = new URL("http://stackoverflow.com/questions/88326/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(true);

System.out.println(conn.getURL().toString());

The output is:

stackoverflow.com/questions/88326/does-elmah-handle-caught-exceptions-as-well

It works well for the Stack Overflow website, but for the sears.com site, it doesn't work.

If we enter the URL blow:

http://www.sears.com/search=iphone

the output is still:

http://www.sears.com/search=iphone

But actually, the page will redirect to:

http://www.sears.com/tvs-electronics-phones-all-cell-phones/s-1231477012?keyword=iphone&autoRedirect=true&viewItems=25&redirectType=CAT_REC_PRED

How can I solve this problem?

Edit
Report