// use this to encode the username/password
private String encodeAuthorization String username, String password)
{
String authorization = username + ":" + password;
sun.misc.BASE64Encoder enCoder = new sun.misc.BASE64Encoder();
return "Basic " + enCoder.encode(authorization.getBytes());
}
// insert this piece into setting the connection properties, where encodedAuthorization is a result of the function given above:
connection.setRequestProperty("Authorization", encodedAuthorization);