Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Authenticator Problem: ProtocolException: Server redirected too many times

843790Oct 12 2009 — edited Oct 15 2009
My program needs to login to a certain website, and I'm using Authenticator to do this. If I supply valid credentials this works fine. However, my program needs to handle the case of the user entering invalid credentials. The site responds to invalid logins by redirecting to itself. If I type the URL into a browser, I get a login prompt, and if I enter an invalid login, it just reloads the page and gives me a new login prompt.

Since java automatically tries to login to every page with the given authenticator, it gets stuck in a loop. Login, redirected to same site, login again, etc. until this exception is thrown:
java.net.ProtocolException: Server redirected too many times (20)

What's the best way to handle this? I've tried adding
HttpURLConnection.setFollowRedirects(false);
but it doesn't seem to work (it still redirects).
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 12 2009
Added on Oct 12 2009
4 comments
1,127 views