Here you can find the source of getHttpConnection(String urlStr, String charSet, Map
public static HttpURLConnection getHttpConnection(String urlStr, String charSet, Map<String, String> props) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.Iterator; import java.util.Map; public class Main { public static HttpURLConnection getHttpConnection(String urlStr, String charSet, Map<String, String> props) throws IOException { URL url = new URL(urlStr); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); for (Iterator iterator = props.keySet().iterator(); iterator.hasNext();) { String k = (String) iterator.next(); connection.addRequestProperty(k, props.get(k)); }//from www . j ava 2 s . c om connection.setRequestMethod("GET"); return connection; } }