2011/01/14

Sending Basic authentication using URL

URL url = new URL(“location address”);
URLConnection conn = url.openConnection();
String authorizationString = "Basic" + Base64.encode("username:password");
conn.setRequestProperty ("Authorization", authorizationString);
InputStream in = conn.getInputStream();
OR
Authenticator.setDefault (new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication ("username", "password".toCharArray());
    }
});