Android Utililty Methods Http Get

List of utility methods to do Http Get

Description

The list of methods to do Http Get are organized into topic(s).

Method

StringgetStringResponseData(HttpResponse httpResponse)
get String Response Data
if (httpResponse == null) {
    return "httpResponse is null!";
} else if (httpResponse.getEntity() == null) {
    return "httpResponse entity is null";
} else {
    return EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
HttpClientgetHttpClient()
Get singleton of HttpClient object.
if (httpClient == null) {
    httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
    ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
return httpClient;
...
voidmaybeCreateHttpClient()
Configures the httpClient to connect to the URL provided.
if (mHttpClient == null) {
    mHttpClient = new DefaultHttpClient();
    final HttpParams params = mHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params,
            REGISTRATION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
    ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
StringsendGetRequest(String path)
send Get Request
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
InputStream inStream = conn.getInputStream();
byte[] data = readInputStream(inStream);
String result = new String(data, "UTF-8");
return result;
...
StringfetchData(String url)
fetch Data
System.out.println("Fetching data from:");
System.out.println(url);
InputStream inputStream = null;
String result = "";
Exception error = null;
try {
    DefaultHttpClient httpclient = new DefaultHttpClient(
            new BasicHttpParams());
...