Exemplo n.º 1
0
  private static UrlResponse doMethod(String requestMethod, String path, String body)
      throws Exception {
    URL url = new URL("http://localhost:" + PORT + path);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(requestMethod);

    // connection.setDoOutput(true);

    connection.connect();
    // connection.getOutputStream().flush();

    String res = IOUtils.toString(connection.getInputStream());
    UrlResponse response = new UrlResponse();
    response.body = res;
    response.status = connection.getResponseCode();
    response.headers = connection.getHeaderFields();
    return response;
  }
Exemplo n.º 2
0
 private void cacheInputStream() throws IOException {
   cachedBytes = IOUtils.toByteArray(super.getInputStream());
 }