Code
package com.codercrunch.andriod.commons.utils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class HttpUtils { public static String getContents(String url) { String contents =""; try { URLConnection conn = new URL(url).openConnection(); InputStream in = conn.getInputStream(); contents = convertStreamToString(in); } catch (MalformedURLException e) { Log.v("MALFORMED URL EXCEPTION"); } catch (IOException e) { Log.e(e.getMessage(), e); } return contents; } private static String convertStreamToString(InputStream is) throws UnsupportedEncodingException { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } }