How do I connect to a remote URL in Java, which requires authentication. I am trying to find a way to modify the code below so that I can provide a username / password in the program so that it can not be added 401.
url = URL = new URL (string format ("http: //% s / manager / list", _host + ": 8080")); HttpURL Connection Connection = (HttpURL Connection) url.openConnection ();
You can set default authenticator for http requests like this:
Authenticator.setDefault (New Authenticator) {Secure PasswordAction getPasswordAuthentication ()} Returns the new passwordEctication ("user name", "password" .to variable ());}}; In addition, if you need more flexibility, you can check it, which will give you more authentication options (as well as session support, etc.) < / Div>
Comments
Post a Comment