Here you can find the source of post(URL url, String content)
public static String post(URL url, String content) throws IOException
//package com.java2s; /*// w w w. j ava 2 s .c om * Copyright ? 2014 - 2016 | Wurst-Imperium | All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.Proxy; import java.net.URL; public class Main { public static String post(URL url, String content) throws IOException { return post(url, content, "application/x-www-form-urlencoded"); } public static String post(URL url, String content, String contentType) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", contentType); connection.setRequestProperty("Content-Length", "" + content.getBytes().length); connection.setRequestProperty("Content-Language", "en-US"); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); DataOutputStream output = new DataOutputStream(connection.getOutputStream()); output.writeBytes(content); output.flush(); output.close(); BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuffer buffer = new StringBuffer(); for (String line; (line = input.readLine()) != null;) { buffer.append(line); buffer.append("\n"); } input.close(); return buffer.toString(); } }