Heys guys, following problem here: I have a username which looks like "ABCD\michael" and a password which looks like "password!6789". "ABCD" in this case is the domain.
With the following code, im getting 401 unauthorized as a response code. I suspect, that the doublebackslashes are not being converted to a single backslash prior the base64 encoding. Or am I using the domain in a wrong way?
I need help to get this working. Help would be appreciated.
Thank you in advance!
public int getMeTheResponseCodeOfURL(final URL url) {
HttpURLConnection httpUrlConnection = null;
int statusCode = 0;
String userName = "ABCD\\michael";
String userPass = "password!6789";
String UserAndPass = userName + ":" + userPass;
String userPassBase64 = Base64.getEncoder().encodeToString(UserAndPass.getBytes());
try {
httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setRequestProperty("Authorization", "Basic " + userPassBase64);
httpUrlConnection.connect();
statusCode = httpUrlConnection.getResponseCode();
} catch (final IOException e) {
this.log.error("IO Exception! Errormessage: " + e);
}
return statusCode;
}