HTTP Requests

A web service wouldn't be a “web” service if we didn't use HTTP to access it. Making an HTTP request on Android is straightforward using the Apache-provided HttpClient classes that are included with Android in the org.apache.http package.

First we need to create an HttpClient object, which will actually be a DefaultHttpClient object.

HttpClient httpclient = new DefaultHttpClient();

Following that, we can construct the request. In this case, we'll be making an HTTP GET request, which puts any parameters on the URL in the form of a query string. This is as opposed to an HTTP POST request, which sends additional data as the body of the request message, which is not part of the URL.

To create an HTTP GET request, we'll instantiate ...

Get Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.