title: How to print a http request as a string in java
body: <p>This is my code which is used connected to URL,its working fine but i want http request in string, , I want know what is actually being sent to the servers</p>
  
  <pre><code>HttpURLConnection conn = null;
                  try {
                  URL url = new URI(baseURL).toURL();
                  conn = (HttpURLConnection) url.openConnection();
                  conn.setRequestMethod("POST");
                  conn.setRequestProperty("User-Agent", "Mozilla/5.0");
                  conn.setRequestProperty("Content-Type",
                          "application/x-www-form-urlencoded");
  
                  conn.setRequestProperty("Content-Length", Integer.toString(builder.toString().length()));
                  conn.setConnectTimeout(10000);
  
                  conn.setReadTimeout(10000);
                  conn.setUseCaches(false);
  
                  OutputStream outputStream = new BufferedOutputStream(conn.getOutputStream());`
                  BufferedWriter writer = new BufferedWriter(
                          new OutputStreamWriter(outputStream, "UTF-8"));
                  writer.write(builder.toString());
                  writer.flush();
                  writer.close();
                  outputStream.close();
                  conn.connect();
                  requestStatusCode = conn.getResponseCode();
              } 
  </code></pre>
  
  <p>I want what is actually being sent to the servers</p>