I am trying to extract the content of a webpage A. Using groovy I’ve tried the following
......
String urlStr = "url-of-webpage-A"
String pageText = urlStr.toURL().text
//println pageText
.....
The above code retrieves the text of webPage A as long as it doesn’t redirect to an other webpage B. If A redirects to B, the page content of webPage B is retrieved in the pageText variable. Is there a way to code and check if webPage A is redirecting to an other webpage (in groovy or java)?
PS: The above piece of code is not a part of server side logic. I am executing it on the client side within the scope of a desktop appilcation.
In groovy, you could do what Joachim suggests by doing:
If you don’t want to be redirected, and want the contents of the first page, you simply need to do: