How to use URLConnection.setAllowUserInteraction()

C

Cameron McCormack

Hi.

I'm trying to work out what URLConnection.setAllowUserInteraction()
actually does. I thought it would have affected whether an
Authenticator would be used to get a username/password if one was
required, but that doesn't seem to be the case.

The test I used was the following:

import java.net.*;
public class AuthTest {
public static void main(String[] args) {
try {
Auth a = new Auth();
Authenticator.setDefault(a);
URL u = new URL("http://mcc.id.au/temp/pw/something");
HttpURLConnection c =
(HttpURLConnection) u.openConnection();
c.setAllowUserInteraction(false);
System.out.println(c.getResponseCode());
} catch (Exception e) {
e.printStackTrace();
}
}
private static class Auth extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println("getPasswordAuthentication() called");
return null;
}
}
}

The URL used is one that requires authentication. Even though I called
setAllowUserInteraction(false), my Authentictor is still called.

Is setAllowUserInteraction() actually the way I should be influencing
whether my Authenticator is called? Or is there another way?

Thanks,

Cameron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top