Как просматривать запросы, отправленные с помощью httpurlconnection?

Я отправляю запросы с помощью httpurlconnection Вопрос заключается в том, могу ли я полностью просматривать весь отправленный мной запрос? Тело, все заголовки и тд

    //Создаем набор необходимых заголовков
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-Type", "application/x-www-form-urlencoded");

    try {
        url = new URL(host);
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        if(headers != null) {
            for (String key : headers.keySet()) {
                String value = headers.get(key);
                con.setRequestProperty(key, value);
            }
        }
        String allheaders = String.valueOf(con.getRequestProperties());

        if(method.equals("POST")) {

            con.setRequestMethod("POST");
            con.setDoOutput(true);
            try (OutputStream os = con.getOutputStream()) {
                byte[] input = body.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
            StringBuilder response = new StringBuilder();
            String responseLine;
            while ((responseLine = br.readLine()) != null) {
                response.append(responseLine.trim());
                result = response.toString();
            }
        }

        // Вывести заголовки - System.out.println(con.getRequestProperties());

        //--------------------Информация о запросе---------------------
        System.out.println("Response code: " + con.getResponseCode());
        System.out.println("Request Method: " + con.getRequestMethod());
        System.out.println("Request host: " + host);
        System.out.println("Request headers: " + allheaders);
        System.out.println("Response Headers: " + con.getHeaderFields());
        System.out.println(result);

        //System.out.println(result);
        isR = new InputStreamReader(con.getInputStream()); // Тут
        bfR = new BufferedReader(isR);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        assert isR != null;
        isR.close();
        assert bfR != null;
        bfR.close();
    }
}

}


Ответы (0 шт):