code: public static HttpResponse getResponse(String urls, HttpRequest request,
                                             HttpMethod method, int connectTimeoutMillis, int readTimeoutMillis) throws IOException {
          OutputStream out = null;
          InputStream content = null;
          HttpResponse response = null;
          HttpURLConnection httpConn = request
              .getHttpConnection(urls, method.name());
          httpConn.setConnectTimeout(connectTimeoutMillis);
          httpConn.setReadTimeout(readTimeoutMillis);
  
          try {
              httpConn.connect();
              if (null != request.getPayload() && request.getPayload().length > 0) {
                  out = httpConn.getOutputStream();
                  out.write(request.getPayload());
              }
              content = httpConn.getInputStream();
              response = new HttpResponse();
              parseHttpConn(response, httpConn, content);
              return response;
          } catch (SocketTimeoutException e) {
              throw e;
          } catch (IOException e) {
              content = httpConn.getErrorStream();
              response = new HttpResponse();
              parseHttpConn(response, httpConn, content);
              return response;
          } finally {
              if (content != null) {
                  content.close();
              }
              httpConn.disconnect();
          }
      }
docs: Get http response