public static void post ( URL url , String params ) throws IOException { URLConnection conn = url . openConnection ( ) ; if ( conn instanceof HttpURLConnection ) { ( ( HttpURLConnection ) conn ) . setRequestMethod ( "POST" ) ; conn . setRequestProperty ( "Content-Type" , "application/json" ) ; } OutputStreamWriter writer = null ; try { conn . setDoOutput ( true ) ; writer = new OutputStreamWriter ( conn . getOutputStream ( ) , Charset . forName ( "UTF-8" ) ) ; // write parameters writer . write ( params ) ; writer . flush ( ) ; } finally { if ( writer != null ) { writer . close ( ) ; } } }
Executes the given request as a HTTP POST action .