Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created December 6, 2013 15:47
Show Gist options
  • Save deckerego/7826915 to your computer and use it in GitHub Desktop.
Save deckerego/7826915 to your computer and use it in GitHub Desktop.
HTTP authentication should be performed according to RFC 2617. This specifies that: - An "Authorization" name/value pair is added to the HTTP header - The value of the Authorization header is a token consisting of the authorization scheme plus authentication token - The authentication token is the value username:password, encoded as a base64 str…
String authToken = new BASE64Encoder().encode(username + ":" + password);
URLConnection urlConnection = url.getUrl().openConnection();
urlConnection.setDoOutput(true);
urlConnection.setConnectTimeout(5000);
urlConnection.setRequestProperty("Authorization", "Basic "+authToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment