Here you can find the source of getJsonFromUrlWithJsonParameter(String url, String jsonRequest)
public static String getJsonFromUrlWithJsonParameter(String url, String jsonRequest) 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.HttpURLConnection; import java.net.URL; public class Main { public static String getJsonFromUrlWithJsonParameter(String url, String jsonRequest) throws IOException { URL urll = new URL(url); HttpURLConnection conn = (HttpURLConnection) urll.openConnection(); //conn.setRequestProperty("Accept", "application/json"); conn.setRequestProperty("Content-Type", "application/json"); //conn.setDoInput (true); conn.setDoOutput(true);/*from www . ja v a 2s . com*/ //conn.connect(); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(jsonRequest); out.close(); /*if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); }*/ BufferedReader br; try { br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); } catch (Throwable e) { br = new BufferedReader(new InputStreamReader(conn.getErrorStream())); } String output; StringBuilder stringa = new StringBuilder(); while ((output = br.readLine()) != null) { stringa.append(output); } conn.disconnect(); return stringa.toString(); } }