将 java.net.URLConnection 与 GET 一起使用,如何获得重定向 URL?

Using java.net.URLConnection with a GET, how to get redirect URL?

使用 java.net.URLConnection,在特定 URL 上使用 GET,此特定 URL 将重定向到新页面。我如何从响应中获取新的 URL?

鉴于 Rishal 的 link 和 amobiz 的回答正是我要找的:

URLConnection con = new URL( url ).openConnection();
System.out.println( "orignal url: " + con.getURL() );
con.connect();
System.out.println( "connected url: " + con.getURL() );
InputStream is = con.getInputStream();
System.out.println( "redirected url: " + con.getURL() );
is.close();