#public String post(HttpPost request, String postData) throws PostageAppException { request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); request.addHeader(HttpHeaders.USER_AGENT, this.getUserAgent()); HttpResponse postResponse; try { request.setEntity(new StringEntity(postData)); postResponse = this.httpClient.execute(request); if (postResponse.getStatusLine().getStatusCode() / 100 != 2) { throw new PostageAppException("Unable to connect to PostageApp servers for API endpoint " + request.getURI().toString()); } try { return IOUtils.toString(postResponse.getEntity().getContent()); } catch (Exception e) { throw new PostageAppException(e.getMessage()); } } catch (Exception e) { throw new PostageAppException(e.getMessage()); } finally { if (httpClient != null) { request.releaseConnection(); httpClient.getConnectionManager().closeExpiredConnections(); } } }
Activity