HTTP client for Android providing both synchronous (blocking) and asynchronous interfaces so it can be used on or off the UI thread.
Synchronous (for use off the UI thread in an
Sample usage:
**********************Synchronous (for use off the UI thread in an
AsyncTask or Runnable)AndroidHttpClient httpClient = new AndroidHttpClient("http://www.google.com");
ParameterMap params = httpClient.newParams().add("q", "GOOG");
HttpResponse httpResponse = httpClient.get("/finance", params);
System.out.println(httpResponse.getBodyAsString());
**********************Asynchronous (can be used anywhere, automatically wraps in an
AsyncTask)AndroidHttpClient httpClient = new AndroidHttpClient("http://www.google.com");
ParameterMap params = httpClient.newParams().add("q", "GOOG");
httpClient.setMaxRetries(3);
httpClient.get("/finance", params, new AsyncCallback() {
public void onComplete(HttpResponse httpResponse) {
System.out.println(httpResponse.getBodyAsString());
}
public void onError(Exception e) {
e.printStackTrace();
}
});
No comments:
Post a Comment