Using java.net.URLConnection, with a GET on a specific URL, this specific URL will redirect to a new page. How do I get that new URL from the response?
Asked
Active
Viewed 155 times
1
-
1possible duplicate of [https://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url](https://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url) may be this u need – Rishal Mar 26 '18 at 13:18
1 Answers
0
Given Rishal's link and amobiz's answer was what I was looking for:
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();

Tim Nuwin
- 2,775
- 2
- 29
- 63