Proxy Authentication - Cannot login as multiple users
I have a class that open connections to URLs through a proxy. The proxy requires authentication, using NTLM protocol.
I need to connect to one URL with a specific username and password, and then to another URL with another username/password combination.
I tried using the java.net.Authenticator class, but found out that there is no option to change the credentials when using it. Meaning that if I sent correct username and password, all the next connections will use these credentials, and ignore the other credentials I supply.
Then I tried using the "Authorization" request property, like that:
String userPassword = username + ":" + password;
String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
urlConnection.setRequestProperty("Authorization", "Basic " + encoding);
This also does not solve the problem. :(
I test it like that: I send wrong credentials, and get 407 response code. Then I send correct credentials and get 200 response code. Then I send wrong credentials again, and I get 200.
I follow redirections and I see that for every URL the proxy requests for username and password, so this is not a proxy problem.
How can it be that the correct username and password are "remembered"?