Java tutorial
//package com.java2s; //License from project: Apache License import org.json.JSONObject; import java.io.DataOutputStream; import java.net.HttpURLConnection; import java.nio.charset.Charset; public class Main { private static HttpURLConnection defineHttpsURLConnection(HttpURLConnection connection, JSONObject jsonObject) { try { connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); /* Add headers to the request */ connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.write(jsonObject.toString().getBytes(Charset.forName("UTF-8"))); wr.flush(); wr.close(); } catch (Exception e) { e.printStackTrace(); } return connection; } }