• Post Reply Bookmark Topic Watch Topic
  • New Topic

Detecting URL redirection using java  RSS feed

 
Talib Jockey
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I detect URL redirections using Java. I have to store the final URLs, but ignore the URL which does the redirection.
Can someone help???
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing what you're up to ... given a URL string, using an HttpURLConnection to get data from a web site? If so, see getResponseCode to detect a redirect. Codes in the 300s indicate a redirect was done. See http://libraries.ucsd.edu/about/tools/http-response-codes.html or google for "http response code"
You need to know where you realy wound up, too. Maybe set followRedirect to false. Then when you get a 300 something, look through the actual HTML returned for a redirect header. I haven't tried this. Let me know if it works for you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!