Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This simple example abuses a page on <a href="https://www.httpwatch.com/httpgallery/authentication/" rel="noreferrer">HttpWatch</a> since it's more fun with a working public example.</p> <p>The resource in question, <code><a href="https://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?randomgarbage" rel="noreferrer">https://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?randomgarbage</a></code> uses basic auth over HTTPS and can be loaded without authentication failure like this (tested using Android 2.3.7):</p> <pre><code> WebView v = ...; // Your webview goes here. try { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // This test service takes the username "httpwatch" and a random // password. Repeating a password can lead to failure, so we create // a decently random one using UUID. String usernameRandomPassword = "httpwatch:" + UUID.randomUUID().toString(); String authorization = "Basic " + Base64.encodeToString(usernameRandomPassword.getBytes("UTF-8"), Base64.NO_WRAP); map.put("Authorization", authorization); v.loadUrl("https://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?" + System.currentTimeMillis(), map); } catch (UnsupportedEncodingException e) {} </code></pre> <p>This works on ICS and Gingerbread. Don't have access to anything older than that, but <code>loadUrl(String, Map&lt;String,String&gt;)</code> was introduced in API level 8, so I don't see why it shouldn't work for that to.</p> <p><b>Clarification for Nappy:</b></p> <p>To support authentication for subsequent requests you supply a <code>WebViewClient</code> and do the following:</p> <pre><code> webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url, &lt;your map containing the Authorization header&gt;); return true; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload