• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Authenticator problem

Sureshot324

Diamond Member
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).
 
Back
Top