Here you can find the source of doGet(String url, String charset)
Parameter | Description |
---|---|
url | a parameter |
public static String doGet(String url, String charset)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Main { /**/* ww w . j a v a 2s. c om*/ * doGet * @param url * @return */ public static String doGet(String url, String charset) { URL reqUrl = null; URLConnection conn = null; BufferedReader in = null; StringBuffer result = new StringBuffer(); try { reqUrl = new URL(url); conn = reqUrl.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(10000); conn.setDoInput(true); conn.setDoOutput(false); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = null; while ((line = in.readLine()) != null) { result.append(line); } // InputStream is = conn.getInputStream(); // byte[] buf = new byte[1024]; // int i = -1; // while((i=is.read(buf))!=-1) { // result.append(new String(buf, 0, i)); // } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } in = null; } } return result.toString(); } }