Here you can find the source of postUrl(URL url, String data)
public static String postUrl(URL url, String data) throws IOException
//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.net.URL; import java.net.URLConnection; public class Main { public static String postUrl(URL url, String data) throws IOException { OutputStreamWriter wr = null; BufferedReader rd = null; try {/* w w w. ja v a 2 s.co m*/ URLConnection conn = url.openConnection(); conn.setDoOutput(true); wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Get the response rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line = null; while ((line = rd.readLine()) != null) { sb.append(line).append("\n"); } return sb.toString(); } finally { if (wr != null) { try { wr.close(); } catch (IOException e) { // NOP } } if (rd != null) { try { rd.close(); } catch (IOException e) { // NOP } } } } }