Here you can find the source of getContentWithPost(String urls, Map
public static String getContentWithPost(String urls, Map<String, String> pv)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.net.URLEncoder; import java.util.Map; public class Main { public static String getContentWithPost(String urls, Map<String, String> pv) { if (pv.isEmpty()) return ""; OutputStreamWriter writer = null; BufferedReader reader = null; try {//w w w . j a va 2 s . c o m String body = ""; for (Map.Entry<String, String> entry : pv.entrySet()) { body += entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8") + "&"; } //System.out.println(body); URL url = new URL(urls); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", String.valueOf(body.length())); writer = new OutputStreamWriter(connection.getOutputStream()); writer.write(body); writer.flush(); reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String content = ""; for (String line; (line = reader.readLine()) != null;) { content += line + "\n"; } return content; } catch (UnsupportedEncodingException uee) { uee.printStackTrace(System.out); } catch (MalformedURLException mue) { mue.printStackTrace(System.out); } catch (ProtocolException pe) { pe.printStackTrace(System.out); } catch (IOException ioe) { ioe.printStackTrace(System.out); } finally { if (writer != null) try { writer.close(); } catch (IOException ioe) { } ; if (reader != null) try { reader.close(); } catch (IOException ioe) { } ; } return ""; } }