Android Http Get handleURLEncodedResponse(HttpResponse response)

Here you can find the source of handleURLEncodedResponse(HttpResponse response)

Description

handle URL Encoded Response

Declaration

public static Map handleURLEncodedResponse(HttpResponse response) 

Method Source Code

//package com.java2s;
import java.io.IOException;

import java.nio.charset.Charset;

import java.util.HashMap;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;

import org.apache.http.client.utils.URLEncodedUtils;

import org.apache.http.protocol.HTTP;

public class Main {
    public static Map handleURLEncodedResponse(HttpResponse 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;//from   w w  w  . jav a  2s . co  m
        HttpEntity entity = response.getEntity();

        System.out.println();
        System.out
                .println("********** URL Encoded Response Received **********");

        for (Map.Entry<String, Charset> entry : set) {
            System.out.println(String.format("  %s = %s", entry.getKey(),
                    entry.getValue()));
            if (entry.getKey().equalsIgnoreCase(HTTP.UTF_8)) {
                charset = entry.getValue();
            }
        }

        try {
            List<NameValuePair> list = URLEncodedUtils.parse(entity);
            for (NameValuePair pair : list) {
                System.out.println(String.format("  %s = %s",
                        pair.getName(), pair.getValue()));
                oauthResponse.put(pair.getName(), pair.getValue());
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new RuntimeException(
                    "Could not parse URLEncoded Response");
        }

        return oauthResponse;
    }
}

Related

  1. request(String url)
  2. requestGet(String url)
  3. executeHttpGet(String url)
  4. executeHttpPost(String url, ArrayList postParameters)
  5. getHTTP(String... params)
  6. handleXMLResponse(HttpResponse response)
  7. getStringFromConnection( HttpURLConnection connection)
  8. httpGetRequestParseParams( String paramString)
  9. formatHttpHeaders(Map headers)