title: How to use java.net.URLConnection to fire and handle HTTP requests
body: <p>Use of <a href="http://docs.oracle.com/javase/8/docs/api/java/net/URLConnection.html" rel="noreferrer"><code>java.net.URLConnection</code></a> is asked about pretty often here, and the <a href="http://download.oracle.com/javase/tutorial/networking/urls/connecting.html" rel="noreferrer">Oracle tutorial</a> is <em>too</em> concise about it.</p>
  <p>That tutorial basically only shows how to fire a <a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods" rel="noreferrer">GET</a> request and read the response. It doesn't explain anywhere how to use it to, among others, perform a <a href="https://en.wikipedia.org/wiki/POST_%28HTTP%29" rel="noreferrer">POST</a> request, set request headers, read response headers, deal with cookies, submit a HTML form, upload a file, etc.</p>
  <p>So, how can I use <code>java.net.URLConnection</code> to fire and handle &quot;advanced&quot; HTTP requests?</p>