Here you can find the source of getConnection(URL url, String method, Map
private static HttpURLConnection getConnection(URL url, String method, Map<String, String> header, String ctype) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.util.Map; import java.util.Map.Entry; public class Main { private static HttpURLConnection getConnection(URL url, String method, Map<String, String> header, String ctype) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false);/* w ww. ja va 2s . c o m*/ conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod(method); // conn.setRequestProperty("Accept", "text/xml,text/javascript"); // conn.setRequestProperty("User-Agent", "iLegendSoft-Test-Client"); conn.setRequestProperty("Content-Type", "application/json"); if (header != null && header.size() > 0) for (Entry<String, String> entry : header.entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } return conn; } }