/** * Perform a GET request and parse the response and return a simple string of the content * * @param path * path to request, can be relative or absolute * @return the entity text * @throws IOException * , HttpResponseException */ public String get(String path) throws IOException, HttpResponseException { HttpResponse response = client.execute(new HttpGet(api(path)), localContext); int status = response.getStatusLine().getStatusCode(); if (status < 200 || status >= 300) { throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase()); } Scanner s = new Scanner(response.getEntity().getContent(), CHARSET_UTF_8); s.useDelimiter("\\z"); StringBuffer sb = new StringBuffer(); while (s.hasNext()) { sb.append(s.next()); } return sb.toString(); }
HttpPost request = new HttpPost(api(path)); if (xml_data != null) { request.setEntity(new StringEntity(xml_data, ContentType.APPLICATION_XML));
/** * Perform a GET request and parse the response to the given class * * @param path * path to request, can be relative or absolute * @param cls * class of the response * @param <T> * type of the response * @return an instance of the supplied class * @throws IOException * , HttpResponseException */ public <T extends BaseModel> T get(String path, Class<T> cls) throws IOException, HttpResponseException { HttpResponse response = client.execute(new HttpGet(api(path)), localContext); int status = response.getStatusLine().getStatusCode(); if (status < 200 || status >= 300) { throw new HttpResponseException(status, response.getStatusLine().getReasonPhrase()); } try { return objectFromResponse(cls, response); } finally { EntityUtils.consume(response.getEntity()); } }
HttpPost request = new HttpPost(api(path)); if (data != null) { StringEntity stringEntity =