Java URL Post writePostRequest(URLConnection connection, String postRequestBody, String contentType)

Here you can find the source of writePostRequest(URLConnection connection, String postRequestBody, String contentType)

Description

write Post Request

License

Open Source License

Declaration

private static void writePostRequest(URLConnection connection, String postRequestBody, String contentType)
            throws IOException 

Method Source Code

//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);
        }
    }
}

Related

  1. postData(URL base, String urlAddress, Map data)
  2. postForString(URL url, String data)
  3. postRequest(URLConnection conn, Map nameValuePairs)
  4. postToUrl(String page)
  5. postUrl(URL url, String data)
  6. xmlPost(String urlStr, String xmlInfo)
  7. writeString(URLConnection connection, String string)