How to authorize to a web server with android and the org.apache.http classes?

I’m trying to authenticate to a web server from an android class with the org.apache.http.HttpClient.

How can I do this? The code for my connection is:

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("url");

HttpResponse response = null;

try {
    response = httpClient.execute(httpGet);
} catch (ClientProtocolException e) {
} catch (IOException e) {
Log.i("httptest", response.getStatusLine().toString());
HttpEntity entity = response.getEntity();


I want to do a basic authentication with username and password


Documentation for HttpClient can be found at the HttpClient site.

You don’t say what sort of authentication you are trying to use, so it is impossible to give you concrete answers. Here are some tutorials that may match your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *