Possible Duplicate:
Java - How to find the redirected url of a url?
大家好,
假设我想知道哪个维基百科页面对应于这个网址: http://en.wikipedia.org/wiki/ireland
如果我用浏览器导航,我可以看到它是 http://en.wikipedia.org/wiki/Ireland 。 有没有办法从 Java 应用程序获取真实的 url?
穆隆
最佳答案
当您创建 HttpURLConnection 时,您可以使用 setInstanceFollowRedirects(boolean) 来阻止连接遵循重定向。如果响应代码在 300 秒内,您可以获得 Location header ,其中包含重定向 URL。
关于java - 从 Java 中的 httprequest 获取重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178453/