title: android webview with https connection and basic auth. How to get this working?
body: <p>I have researched and researched and researched this until I've gone grey and bald.
  How on earth do I get a webview to work for a site that needs http basic authentication over an https connection on api level 8+</p>
  
  <p>I have the following code</p>
  
  <pre><code>    String email = Util.getEmail(this);
      String pwd = Util.getPassword(this);
      webview.getSettings().setJavaScriptEnabled(true);
      webview.setHttpAuthUsernamePassword(Config.SERVER_BASE_URL, "Application", email, pwd);
  
  //      webview.setWebViewClient(new MobileWebViewClient(this));
      webview.loadUrl(url);
  </code></pre>
  
  <p>As you can see I did have a web view client (Now commented out) that overrides the onReceivedHttpAuthRequest method which looks like this</p>
  
  <pre><code>@Override
  public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm){
      String email = Util.getEmail(wvContext);
      String pwd = Util.getPassword(wvContext);
      if(!pwd.equalsIgnoreCase("-1") &amp;&amp; !pwd.equalsIgnoreCase("-1")){
         handler.proceed(email, pwd);
      }
  }
  </code></pre>
  
  <p>This was used without the webview.setHttpAuthUsernamePassword and works fine except that it means 2 requests are issued to the website - The first gets a 401 and then the client kicks in with the authorisation stuff This is fine for a small amount of website traffic but halving the amount of traffic (currently averaging 49 requests p/m) is the name of the game right now!</p>
  
  <p>I read that I can pre-emptively supply the credentials by using</p>
  
  <pre><code>webview.setHttpAuthUsernamePassword(Config.SERVER_BASE_URL, "Application", email, pwd);
  </code></pre>
  
  <p>However this just results in Http Basic: Access denied errors
  The server base url constant is the domain name for the site i.e. <a href="https://example.com" rel="noreferrer">https://example.com</a> (without the page) the actual url is <a href="https://example.com/some_pages" rel="noreferrer">https://example.com/some_pages</a>.
  It makes no difference whether I use the full url or the domain. I have checked the realm and I have that correct and I have used just empty strings providing only email and password.
  Could this be something to do with the fact that the site is using https? My code seems to work fine on my dev box without https but that may be a red herring.!</p>
  
  <p>The only stack overflow questions that seem to cover my requirements have not got accepted answers and the docs are no help that I can see.</p>
  
  <p>I now have such a large dent in my head from banging it against a brick wall that I am thinking of getting a square hat.</p>
  
  <p>Please if anyone can give me the solution to this I will be forever in your debt!
  I might even e-Mail you an KitKat</p>