Here you can find the source of createURLConnection(String url)
public static URLConnection createURLConnection(String url)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.URL; import java.net.URLConnection; public class Main { public static URLConnection createURLConnection(String url) { try {//from ww w. j a va2s.c o m final URL address = new URL(url); final URLConnection connection = address.openConnection(); connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"); connection.setConnectTimeout(5000); connection.setRequestProperty("Content-Type", "image/png"); return connection; } catch (IOException ex) { System.out.println("Error creating connection!"); ex.printStackTrace(); } return null; } }