<span style="font-family: Arial, Helvetica, sans-serif;">/**</span>
* Send a post request to access the local application and return different results according to the passed parameters */ public static void post(String url, List<BasicNameValuePair> formparams) { // Create a default httpClient instance. CloseableHttpClient httpclient = HttpClients.createDefault(); // create httppost HttpPost httppost = new HttpPost(url); // create parameter queue UrlEncodedFormEntity uefEntity; try { uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); httppost.setEntity(uefEntity); System.out.println("executing request" + httppost.getURI()); CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity entity = response.getEntity(); if (entity != null) { System.out.println("--------------------------------------"); System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8")); System.out.println("--------------------------------------"); } } finally { response.close(); } } catch (ClientProtocolException e) { e.printStackTrace (); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace (); } finally { // close the connection and release resources try { httpclient.close(); } catch (IOException e) { e.printStackTrace (); } } }