title: Digest authentication in Android using HttpURLConnection
body: <p>as the question allready says, I am trying to do digest authentication in android.<br>
  Until now i have used the <code>DefaultHttpClient</code> and it's authentication method (using <code>UsernamePasswordCredentials</code> and so on), but it is deprecated since Android 5 and will be removed in Android 6.<br>
  So i am about to switch from <code>DefaultHttpClient</code> to <code>HttpUrlConnection</code>.<br>
  Now i am trying to achieve digest authentication, which should work pretty simple as explained <a href="https://stackoverflow.com/a/1968873/3182091">here</a>:</p>
  
  <pre><code>Authenticator.setDefault(new Authenticator() {
      protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(username, password);
      }
  });
  </code></pre>
  
  <p>But the <code>getPasswordAuthentication</code> gets never called for some reason.<br>
  During my search for this problem i found different posts, saying digest authentication is not supported by the <code>HttpUrlConnection</code> in android, but those posts are from 2010-2012, so i am not sure if this is still true. Also we are using <code>HttpUrlConnection</code> with digest authentication in our desktop java application, where it does work.</p>
  
  <p>I also found some posts, talking about <code>OkHttp</code>. <code>OkHttp</code> seems to be used by Android under the hood (to be more specific the <code>HttpUrlConnectionImpl</code>). But this <code>HttpUrlConnectionImpl</code> is a bit strange, it is not even shown in the Eclipse type hierarchy and i am not able to debug it. Also it should be a <code>com.squareup.okhttp.internal.huc.HttpUrlConnectionImpl</code>, while in android it is a <code>com.android.okhttp.internal.http.HttpUrlConnectionImpl</code>.  </p>
  
  <p>So i am just not able to do digest authentication with this <code>HttpUrlConnection</code> in android.<br>
  Can anyone tell me how to do that without external libraries?</p>
  
  <p><strong>EDIT:</strong><br>
  The server asks for digest authentication:  </p>
  
  <pre><code>WWW-Authenticate: Digest realm="Realm Name",domain="/domain",nonce="nonce",algorithm=MD5,qop="auth"
  </code></pre>
  
  <p>So Basic-Authentication shouldn' work, as the server is asking for digest.</p>