Here you can find the source of getHttpPOSTConnection(String urlStr, String charSet, Map
public static HttpURLConnection getHttpPOSTConnection(String urlStr, String charSet, Map<String, String> props, Map<String, String> params) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Iterator; import java.util.Map; public class Main { public static HttpURLConnection getHttpPOSTConnection(String urlStr, String charSet, Map<String, String> props, Map<String, String> params) 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 w w w . java 2s . co m connection.setRequestMethod("POST"); connection.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); StringBuilder sb = new StringBuilder(); for (Iterator iterator = params.keySet().iterator(); iterator.hasNext();) { String name = (String) iterator.next(); sb.append(name); sb.append("="); sb.append(URLEncoder.encode(params.get(name))); sb.append("\n"); } System.out.println(sb.toString()); writer.write(sb.toString()); writer.close(); return connection; } }