Rohit Mandiwal
Rohit Mandiwal

Reputation: 10462

Android HTTP Authentication

How do I authenticate via HTTP in Android?

Upvotes: 2

Views: 2226

Answers (1)

Rohit Mandiwal
Rohit Mandiwal

Reputation: 10462

I face very much dificuly to authenticate via HTTP in Android as in browser (web and Android native) it worked perfect and ask for credentials but this scene is not in code. so here is the code I used.

URL url = new URL("YOUR URL HERE");


Authenticator.setDefault(new Authenticator(){
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
                 System.err.println("Feeding username and password for " + getRequestingScheme());
                 return (new PasswordAuthentication("username", "password".toCharArray()));
          }});
InputStream stream = url.openStream();

Upvotes: 3

Related Questions