Here you can find the source of readUrl(String url, String token)
public static String readUrl(String url, String token) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String readUrl(String url, String token) throws Exception { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("GET"); //add request header if (token != null) { con.setRequestProperty("X-Auth-Token", token); }//from w w w . j av a 2 s . c o m //int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader( con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); } }