Difference between revisions of "Template:Base Code for Consuming API Using Java"
From Updox API
Line 1: | Line 1: | ||
− | private void SendReceiveJSON( | + | private void SendReceiveJSON(StringEntity params, String uri) throws Exception { |
HttpClient httpClient = new DefaultHttpClient(); | HttpClient httpClient = new DefaultHttpClient(); | ||
try { | try { | ||
− | HttpPost request = new HttpPost( | + | HttpPost request = new HttpPost(uri); |
− | request.addHeader("content-type", " | + | request.addHeader("content-type", "application/json"); |
− | request.setEntity( | + | request.setEntity(params); |
HttpResponse response = httpClient.execute(request); | HttpResponse response = httpClient.execute(request); | ||
} catch (Exception ex) { | } catch (Exception ex) { |
Revision as of 14:10, 18 November 2013
private void SendReceiveJSON(StringEntity params, String uri) throws Exception { HttpClient httpClient = new DefaultHttpClient(); try { HttpPost request = new HttpPost(uri); request.addHeader("content-type", "application/json"); request.setEntity(params); HttpResponse response = httpClient.execute(request); } catch (Exception ex) { // handle exception here } finally { httpClient.getConnectionManager().shutdown(); } }