Here you can find the source of getURL(URL url, String params)
Parameter | Description |
---|---|
url | a parameter |
params | a parameter |
public static String getURL(URL url, String params)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.URL; public class Main { /**/*from ww w. j a v a 2 s .c o m*/ * Get a GET String response * @param url * @param params * @return */ public static String getURL(URL url, String params) { StringBuilder sb = new StringBuilder(); String lineSepatator = null; try { lineSepatator = System.getProperty("line.separator"); } catch (Exception e) { lineSepatator = "\n"; } try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setAllowUserInteraction(false); connection.setDoOutput(false); /* String userpass = "anonymous" + ":" + ""; String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes())); connection.setRequestProperty ("Authorization", basicAuth);*/ InputStream response = connection.getInputStream(); BufferedReader bufReader = new BufferedReader(new InputStreamReader(response)); String sLine; while ((sLine = bufReader.readLine()) != null) { sb.append(sLine); sb.append(lineSepatator); } connection.disconnect(); } catch (ConnectException ctx) { ctx.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return sb.toString(); } }