List of utility methods to do Http Get
String | request(String url) request InputStream inputStream = null; String result = ""; try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse httpResponse = httpclient .execute(new HttpGet(url)); inputStream = httpResponse.getEntity().getContent(); if (inputStream != null) { ... |
HttpURLConnection | requestGet(String url) Sets up and opens a new HttpURLConnection to perform a HTTP GET request. URL getUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) getUrl .openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("GET"); conn.setDoInput(true); return conn; ... |
String | executeHttpGet(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 .getEntity().getContent())); ... |
String | executeHttpPost(String url, ArrayList 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( postParameters); request.setEntity(formEntity); HttpResponse response = client.execute(request); ... |
String | getHTTP(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 " ... |
Map | handleURLEncodedResponse(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(); System.out.println(); System.out .println("********** URL Encoded Response Received **********"); ... |
Map | handleXMLResponse(HttpResponse response) handle XML Response Map<String, String> oauthResponse = new HashMap<String, String>(); try { String xmlString = EntityUtils.toString(response.getEntity()); DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); InputSource inStream = new InputSource(); inStream.setCharacterStream(new StringReader(xmlString)); ... |
String | getStringFromConnection( HttpURLConnection connection) get String From Connection InputStream inputStream = new BufferedInputStream( connection.getInputStream()); String jsonString = convertStreamToString(inputStream); inputStream.close(); return jsonString; |
HashMap | httpGetRequestParseParams( 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); ... |
String | formatHttpHeaders(Map Formats HTTP headers. StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> header : headers.entrySet()) { sb.append(String.format("%s : %s\n", header.getKey(), header.getValue())); return sb.toString(); |