1

Consider this URL http://dx.doi.org/10.1006/jpdc.1997.1383. When I put it in the browser address bar and press enter, the URL will change into http://www.sciencedirect.com/science/article/pii/S0743731597913836. Using Java, how can I get the second URL address?

2

2 Answers 2

2

Simply call getUrl() on URLConnection instance after calling getInputStream()

Sign up to request clarification or add additional context in comments.

Comments

1
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();

2 Comments

what is the point of InputStream is = con.getInputStream();? you even did not use it. and you dont have to. Just write con.getInputStream();
You are kind a interacting with the source ( this way you are knowing the precise end point ). So if it is redicted, con.getURL() will be different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.