Java
Chilkat2 Java
Clear REST Authentication Settings
See more REST Examples
Demonstrates Rest.ClearAuth, which removes any authentication providers and credentials previously configured through the SetAuth* methods.
Background. Clearing authentication is useful when reusing a Rest object for a request that must be sent without credentials, or before switching to a different authentication method.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Rest;
public class ChilkatExample {
public static void main(String[] args) {
Rest rest = new Rest();
boolean bTls = true;
boolean bAutoReconnect = true;
try {
rest.connect("example.com", 443, bTls, bAutoReconnect);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
String username = "myUsername";
String password = "myPassword";
try {
rest.setAuthBasic(username, password);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// ClearAuth removes any authentication providers and credentials previously configured through the
// SetAuth* methods, for example before reusing the object for an unauthenticated request.
rest.clearAuth();
System.out.println("Authentication cleared.");
}
}