Java HttpURLConnection setAuthenticator

The setAuthenticator(Authenticator auth) is a method of Java HttpURLConnection class. This method is used to set the authentication request through HTTP protocol. If no authentication is sent then default authentication is used.

Syntax

Parameter

Auth - It is used by this HttpURLConnection.

Throw

UnsupportedOperationException - This exception occurred when implementation of authentication is not supported.

IllegalStateException - This exception occurred when URLConnection is already connected.

NullPointerException - This exception occurred when the supplied auth is null.

Example 1

Test it Now

Output:

https://www.javatpoint.com
Basic :SmF2YXRwb2ludDoxMjM=

Example 2

Test it Now

Output:

https://www.facebook.com
Basic : ZmFjZWJvb2s6NTYz




Latest Courses