Here you can find the source of writePostRequest(URLConnection connection, String postRequestBody, String contentType)
private static void writePostRequest(URLConnection connection, String postRequestBody, String contentType) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.DataOutputStream; import java.io.IOException; import java.net.URLConnection; public class Main { private static void writePostRequest(URLConnection connection, String postRequestBody, String contentType) throws IOException { connection.setDoOutput(true); // whether we want to write to the connection if (contentType != null) { connection.setRequestProperty("Content-Type", contentType); }// w w w . j av a2 s . co m // Note: Content-Length is set implicitly by URLConnection try (DataOutputStream out = new DataOutputStream(connection.getOutputStream())) { out.writeBytes(postRequestBody); } } }