• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Detecting URL redirection using java

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic