Here you can find the source of doGet(String urlString)
public static String doGet(String urlString)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static int connectionTimeOut = 30 * 1000; private static int timeOut = 30 * 1000; public static String doGet(String urlString) { InputStream is = null;//w ww .j a va 2 s. com BufferedReader reader = null; try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Accept-Charset", "utf-8"); conn.setRequestProperty("Content-Type", "application/json"); conn.setConnectTimeout(connectionTimeOut); conn.setReadTimeout(timeOut); StringBuffer buffer = new StringBuffer(); String line = null; conn.connect(); is = conn.getInputStream(); // inputStreamReader = new InputStreamReader(inputStream); reader = new BufferedReader(new InputStreamReader(is)); while ((line = reader.readLine()) != null) { buffer.append(line); } tryClose(is); tryClose(reader); return buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } private static void tryClose(InputStream is) { try { if (null != is) { is.close(); is = null; } } catch (Exception e) { e.printStackTrace(); } } private static void tryClose(java.io.Reader reader) { try { if (null != reader) { reader.close(); reader = null; } } catch (Exception e) { e.printStackTrace(); } } }