Here you can find the source of fetchData(String url)
public static String fetchData(String url) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.BasicHttpParams; public class Main { public static String fetchData(String url) throws Exception { System.out.println("Fetching data from:"); System.out.println(url);/*from ww w .j a v a 2s. c o m*/ InputStream inputStream = null; String result = ""; Exception error = null; try { DefaultHttpClient httpclient = new DefaultHttpClient( new BasicHttpParams()); HttpGet httpget = new HttpGet(new URL(url).toURI()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); inputStream = entity.getContent(); BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } result = sb.toString(); } catch (Exception e) { error = e; } finally { try { if (inputStream != null) inputStream.close(); } catch (Exception squish) { // } } if (error != null) { throw error; } return result; } }