public static String post ( String url , Map < String , String > customHeaders , Map < String , String > params ) throws IOException , HTTPException { LOGGER . log ( Level . INFO , "Sending POST request to the url {0}" , url ) ; HttpPost httpPost = new HttpPost ( url ) ; populateHeaders ( httpPost , customHeaders ) ; if ( params != null && params . size ( ) > 0 ) { List < NameValuePair > nameValuePairs = new ArrayList <> ( ) ; for ( Map . Entry < String , String > param : params . entrySet ( ) ) { nameValuePairs . add ( new BasicNameValuePair ( param . getKey ( ) , param . getValue ( ) ) ) ; } httpPost . setEntity ( new UrlEncodedFormEntity ( nameValuePairs ) ) ; } HttpClient httpClient = HttpClientBuilder . create ( ) . build ( ) ; HttpResponse httpResponse = httpClient . execute ( httpPost ) ; int statusCode = httpResponse . getStatusLine ( ) . getStatusCode ( ) ; if ( isErrorStatus ( statusCode ) ) { String jsonErrorResponse = EntityUtils . toString ( httpResponse . getEntity ( ) , StandardCharsets . UTF_8 ) ; throw new HTTPException ( statusCode , httpResponse . getStatusLine ( ) . getReasonPhrase ( ) , jsonErrorResponse ) ; } return EntityUtils . toString ( httpResponse . getEntity ( ) , StandardCharsets . UTF_8 ) ; }
Send post request .