开发者

Get redirect from httprequest in Java [duplicate]

This question already has answers here: Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜