title: How to handle HTTP authentication using HttpURLConnection?
body: <p>I'm writing a Java client that POSTs to a HTTP server that requires <strong>authentication</strong>.<br>
  I have to support at least the following three authentication methods: Basic, Digest or Negotiate. Additionally the POST may be very large (over 2MB), so I need to use streaming. 
  As is documented for <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/net/HttpURLConnection.html#setFixedLengthStreamingMode(int)" rel="noreferrer">HttpURLConnection</a></p>
  
  <blockquote>
    <p>When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required.</p>
  </blockquote>
  
  <p>So, I need to handle authentication myself. I searched, and searched again, for a way to employ the, already coded, classes - but found no way...</p>
  
  <p>I could just pluck the needed sources from <a href="http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/f7afe7a5e086/src/share/classes/sun/net/www/protocol/http/" rel="noreferrer">here</a> (as they are GPLv2 with Classpath exception). Is this the right way?</p>
  
  <p>Thanks.</p>