Here you can find the source of postForString(URL url, String data)
public static String postForString(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 postForString(URL url, String data) throws IOException { String result = ""; // System.out.println(); URLConnection conn = url.openConnection(); conn.setDoOutput(true);// ww w . j a v a 2 s .co m OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { result += line + "\n"; } wr.close(); rd.close(); return result; } }