How to get correct html base url after forward?
Hello guys!I'm playing around with some code that reads content from a URL like:
URL nu;
try {
nu = new URL("http://www.nu/");
BufferedReader in = new BufferedReader(
new InputStreamReader(nu.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
How ever I would like to detect the html base URL for the response.
If you go to http://www.nu/ in a browser you will see that there is a "forward" to the correct URL http://www.nunames.nu/
Is there a way to find out the "new" URL for the response?
I have tried like:
System.out.println(nu.getHost());
System.out.println(nu.getPath());
System.out.println(nu.toURI().getHost());
System.out.println(nu.toURI().getPath());
Best regards
Fredrik