Skip to content

Instantly share code, notes, and snippets.

@keiji
Created March 9, 2012 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keiji/2005616 to your computer and use it in GitHub Desktop.
Save keiji/2005616 to your computer and use it in GitHub Desktop.
Basic auth
try {
String encodedAuth = Base64.encodeBytes((AUTH_USER_NAME + ":" + AUTH_PASSWORD)
.getBytes());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setRequestProperty("Authorization", "Basic " + encodedAuth);
connection.setRequestMethod("GET");
connection.connect();
return connection.getInputStream();
} catch (ProtocolException e) {
Log.e(LOG_TAG, "ProtocolException", e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment