Android Utililty Methods Http Get

List of utility methods to do Http Get


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


Stringrequest(String url)
InputStream inputStream = null;
String result = "";
try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse httpResponse = httpclient
            .execute(new HttpGet(url));
    inputStream = httpResponse.getEntity().getContent();
    if (inputStream != null) {
HttpURLConnectionrequestGet(String url)
Sets up and opens a new HttpURLConnection to perform a HTTP GET request.
URL getUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) getUrl
return conn;
StringexecuteHttpGet(String url)
Performs an HTTP GET request to the specified url, and return the String read from HttpResponse.
BufferedReader in = null;
try {
    HttpClient client = getHttpClient();
    HttpGet request = new HttpGet();
    request.setURI(new URI(url));
    HttpResponse response = client.execute(request);
    in = new BufferedReader(new InputStreamReader(response
StringexecuteHttpPost(String url, ArrayList postParameters)
Performs an HTTP Post request to the specified url with the specified parameters, and return the string from the HttpResponse.
BufferedReader in = null;
try {
    HttpClient client = getHttpClient();
    HttpPost request = new HttpPost(url);
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
    HttpResponse response = client.execute(request);
StringgetHTTP(String... params)
Performs an HTTP GET Request.
HttpClient httpclient = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(params[0]); 
Log.d("getHTTP():param[1]", params[1]);
Log.d("getHTTP():param[2]", params[2]);
String credentials = params[1] + ":" + params[2];
String base64EncodedCredentials = Base64.encodeToString(
        credentials.getBytes(), Base64.NO_WRAP);
request.addHeader("Authorization", "Basic "
MaphandleURLEncodedResponse(HttpResponse response)
handle URL Encoded Response
Map<String, Charset> map = Charset.availableCharsets();
Map<String, String> oauthResponse = new HashMap<String, String>();
Set<Map.Entry<String, Charset>> set = map.entrySet();
Charset charset = null;
HttpEntity entity = response.getEntity();
        .println("********** URL Encoded Response Received **********");
MaphandleXMLResponse(HttpResponse response)
handle XML Response
Map<String, String> oauthResponse = new HashMap<String, String>();
try {
    String xmlString = EntityUtils.toString(response.getEntity());
    DocumentBuilderFactory factory = DocumentBuilderFactory
    DocumentBuilder db = factory.newDocumentBuilder();
    InputSource inStream = new InputSource();
    inStream.setCharacterStream(new StringReader(xmlString));
StringgetStringFromConnection( HttpURLConnection connection)
get String From Connection
InputStream inputStream = new BufferedInputStream(
String jsonString = convertStreamToString(inputStream);
return jsonString;
HashMaphttpGetRequestParseParams( String paramString)
http Get Request Parse Params
HashMap<String, String> result = new HashMap<String, String>();
paramString = paramString.trim();
if (paramString.length() > 0) {
    String[] params = paramString.replace('+', ' ').split("&");
    for (String param : params) {
        int index = param.indexOf('=');
        if (index >= 0) {
            String name = param.substring(0, index);
StringformatHttpHeaders(Map headers)
Formats HTTP headers.
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> header : headers.entrySet()) {
    sb.append(String.format("%s : %s\n", header.getKey(),
return sb.toString();