Here you can find the source of createConnection(URL url)
public static String createConnection(URL url) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class Main { public static String createConnection(URL url) throws IOException { URLConnection connection = url.openConnection(); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"); connection.addRequestProperty("Content-Type", "application/json"); connection.addRequestProperty("Content-Encoding", "gzip"); connection.addRequestProperty("Accept", "application/json"); connection.addRequestProperty("Connection", "close"); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = null;//from w w w.j a v a 2 s . c o m StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line); } return sb.toString(); } }