Get redirect from httprequest in Java [duplicate]
Possible Duplicate:
Java - How to find the redirected url of a url?
Hi all,
Let's say I want to know which Wikipedia page corresponds to this url: http://en.wikipedia.org/wiki/ireland
If I navigate it with a browser, I can see that it's htt开发者_JAVA百科p://en.wikipedia.org/wiki/Ireland. is there a way to get the real url from a Java application?
Mulone
When you create an HttpURLConnection you can use setInstanceFollowRedirects(boolean) to prevent the connection to follow the redirect. If the response code is in the 300s, you can get the Location header which will have the redirect URL.
Try turning URL redirect off in your browser - the exact configuration depends on your installed one for this.
[edit] If you want to do in Java - you can turn off automated HTTP redirects via getFollowRedirects() option.
http://download.oracle.com/javase/1.4.2/docs/api/java/net/HttpURLConnection.html
精彩评论