I'm in trouble with Authenticator Android Method.
This method works and return 200 Code (HTTP_OK
):
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("admin", "1234".toCharArray());
}
});
but to become dinamically i sent the user values:
urlConnection = new URL(params[0]);
user = params[1];
pass = params[2];
changed the authentication to:
return new PasswordAuthentication(user, pass.toCharArray())
made a test: user/pass: "test".
I want to receive a 401 Code (HTTP_UNAUTHORIZED
)
when i debug and click f7/f8 sometimes i can see the 401 in response code, but i can't return it, because it seems that he enter in a loop inside:
httpUrlConnection.getResponseCode();
Here is a fragment of my code:
.....
httpUrlConnection.setConnectTimeout(2000);
httpUrlConnection.connect();
statusCode = httpUrlConnection.getResponseCode(); //debug stop here
httpUrlConnection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return statusCode;
Any tips?