public Result<InputStream> getInputStream(String endpoint) throws IOException {
   HttpClient cli = createClient();
   HttpGet get = createGet(endpoint);
   HttpResponse res = cli.execute(get);
   Object result = null;
   if (res.getStatusLine().getStatusCode() == 200) result = res.getEntity().getContent();
   else {
     RestResponse resp = new RestResponse(res);
     result = unmarshalPOJO(resp, InputStream.class);
     cli.getConnectionManager().shutdown();
   }
   return new Result<InputStream>(result);
 }
示例#2
0
  public String getRequest(String url, String queryString) {
    String responseText = "";

    try {
      httpGet.setURI(new URI(url + "?" + queryString));
      httpGet.addHeader("Accept", "application/json");

      HttpResponse response = httpClient.execute(httpGet);
      responseText = EntityUtils.toString(response.getEntity());

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    } catch (URISyntaxException e1) {
    }

    return responseText;
  }
示例#3
0
  public String postRequest(String url, List<NameValuePair> entity) {
    String responseText = "";

    try {
      httpPost.setURI(new URI(url));
      httpPost.addHeader("Accept", "application/json");
      httpPost.setEntity(new UrlEncodedFormEntity(entity));

      HttpResponse response = httpClient.execute(httpPost);
      responseText = EntityUtils.toString(response.getEntity());

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    } catch (URISyntaxException e1) {
    }

    return responseText;
  }