List of utility methods to do Http Get
String | getStringResponseData(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"); |
HttpClient | getHttpClient() 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; ... |
void | maybeCreateHttpClient() 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); |
String | sendGetRequest(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; ... |
String | fetchData(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()); ... |