Skip to content

Instantly share code, notes, and snippets.

@DevJonny
Created September 16, 2012 08:58
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 DevJonny/3731666 to your computer and use it in GitHub Desktop.
Save DevJonny/3731666 to your computer and use it in GitHub Desktop.
Android how to get HTTP 401 response
final HttpGet loginDetailsGet = new HttpGet("{your URL to pass login details to}");
loginDetailsGet.addHeader("accept", "application/json");
final HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5 * 1000);
final Credentials credentials = new UsernamePasswordCredentials(username, password);
final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(httpParameters);
defaultHttpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials);
final HttpResponse serverResponse = defaultHttpClient.execute(loginDetailsGet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment