Search code examples
javahttpurlconnectionbasic-authentication

How to avoid JVM opening auth window when HttpURLConnection hits 401


I am using java.net.HttpURLConnection, and it annoyingly presents a window asking for username and password whenever a 401 response code is returned by the HTTP server.

How can I get rid of this automatic auth dialog? I want to handle 401s myself.

I tried setAllowUserInteraction(false), but it seems to have no effect.


Solution

  • The popup comes from the default authenticator. To remove the popup, you can plug in your own authenticator. See How to handle HTTP authentication using HttpURLConnection?