Difference between revisions of "Template:Base Code for Consuming API Using Java"

From Updox API
Jump to: navigation, search
Line 1: Line 1:
private void SendReceiveJSON(String json, String url) throws Exception {  
+
  private void SendReceiveJSON(String json, String url) throws Exception {  
    HttpClient httpClient = new DefaultHttpClient();
+
    HttpClient httpClient = new DefaultHttpClient();
    try {
+
    try {
      HttpPost request = new HttpPost("{{Base url api|ping|ping}}");
+
      HttpPost request = new HttpPost("{{Base url api|ping|ping}}");
      StringEntity params = new StringEntity("{}");
+
      StringEntity params = new StringEntity("{}");
      request.addHeader("content-type", "text/json");
+
      request.addHeader("content-type", "text/json");
      request.setEntity(params);
+
      request.setEntity(params);
      HttpResponse response = httpClient.execute(request);
+
      HttpResponse response = httpClient.execute(request);
    } catch (Exception ex) {
+
    } catch (Exception ex) {
      // handle exception here
+
      // handle exception here
    } finally {
+
    } finally {
      httpClient.getConnectionManager().shutdown();
+
      httpClient.getConnectionManager().shutdown();
    }
+
    }
 
   }
 
   }

Revision as of 12:15, 18 November 2013

 private void SendReceiveJSON(String json, String url) throws Exception { 
    HttpClient httpClient = new DefaultHttpClient();
    try {
      HttpPost request = new HttpPost("https://updoxqa.com/io/ping");
      StringEntity params = new StringEntity("{}");
      request.addHeader("content-type", "text/json");
      request.setEntity(params);
      HttpResponse response = httpClient.execute(request);
    } catch (Exception ex) {
      // handle exception here
    } finally {
      httpClient.getConnectionManager().shutdown();
    }
 }