Here you can find the source of getOutputFromUrlConnection(String stringUrl, String requestProperty)
public static String getOutputFromUrlConnection(String stringUrl, String requestProperty)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { public static String getOutputFromUrlConnection(String stringUrl, String requestProperty) { String outputString = null; try {/*w w w . j ava2 s . c o m*/ URL url = new URL(stringUrl); HttpURLConnection conn = (HttpURLConnection) url .openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", requestProperty); conn.connect(); if (conn.getResponseCode() != 200) { return "0"; } BufferedReader br = new BufferedReader(new InputStreamReader( (conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = br.readLine()) != null) { sb.append(line); } outputString = sb.toString(); br.close(); conn.disconnect(); } catch (MalformedURLException malformedException) { malformedException.printStackTrace(); } catch (IOException ioException) { ioException.printStackTrace(); } return outputString; } }