title: Java: Display request of an HttpURLConnection before sending
body: <p>I want to make some API calls to a server using <code>HttpURLConnection</code>. But the requests are not successful, returning:</p>
  
  <pre><code>&lt;error&gt;
    &lt;http_status&gt;400 Bad Request&lt;/http_status&gt;
    &lt;message&gt;Unexpected request Content-Type header ''. Expecting 'application/x-www-form-urlencoded'.&lt;/message&gt;
  &lt;/error&gt;
  </code></pre>
  
  <p>So I want to check what the "real" content is that is being sent to the server. By real content I mean the exact HTTP request.</p>
  
  <p>Any ideas how I can see this?</p>
  
  <p><strong>Edit:</strong>
  Based on the first answers here I should clarify my problem: I want to avoid using an external program like HTTP sniffer or anything and I was hoping that there is a function or a property or whatever that holds the information I am looking for.</p>
  
  <p>If that is not the case, does someone know if this information can be manually rebuilt (for example by calling several functions like getRequestMethod(), etc.)</p>
  
  <p>I am facing this problem kinda often so that it's worth the effort to build such functionality myself. Just need to know how :)</p>