Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With <a href="https://stackoverflow.com/questions/4488338/webview-android-proxy">WebView android proxy</a> configuration, for basic scheme preemptive proxy authentication,</p> <p>Starting from Android 2.2, the extra header can be set for authentication. The following can add a header for <code>webView</code>'s http request:</p> <pre><code> public void loadUrl(WebView view, String url, String proxyUserName, String proxyPassword){ UsernamePasswordCredentials creds= new UsernamePasswordCredentials(proxyUserName, proxyPassword); Header credHeader = BasicScheme.authenticate(creds, "UTF-8", true); Map&lt;String, String&gt; header = new HashMap&lt;String, String&gt;(); header.put(credHeader.getName(), credHeader.getValue()); view.loadUrl(url, header); } </code></pre> <p>For older version, the preemptive proxy authentication can be set on <code>mProxyUserName</code> and <code>mProxyPassword</code> in <code>android.webkit.Network</code> by reflection:</p> <pre><code>public void loadUrl(WebView view, String url, String proxyUserName, String proxyPassword){ try{ Class networkClass = Class.forName("android.webkit.Network"); if (networkClass != null) { Object networkObj = invokeMethod(networkClass, "getInstance", new Object[]{view.getContext()}, Context.class); if (networkObj != null) { Field mProxyUserName = obj.getClass().getDeclaredField("mProxyUserName"); mProxyUserName.setAccessible(true);mProxyUserName.set(networkObj, proxyUserName); Field mProxyPassword = obj.getClass().getDeclaredField("mProxyPassword"); mProxyPassword.setAccessible(true);mProxyPassword.set(networkObj, proxyPassword); } } }catch(Exception e){ e.printStackTrace(); } view.loadUrl(url); } </code></pre> <p>When you load a new url, both <code>loadUrl()</code> must need to call again. That is very important. Therefore, a custom <code>WebViewClient</code> should be used to override <code>shouldOverrideUrlLoading(WebView view, String url)</code> </p> <pre><code>class ProxyAuthWebViewClient extends WebViewClient { String proxyUserName; String proxyPassword; public ProxyAuthWebViewClient(String proxyUserName, String proxyPassword){ this.proxyUserName = proxyUserName; this.proxyPassword = proxyPassword; } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { loadUrl(view, url, proxyUserName, proxyPassword); return true ; } } </code></pre> <p>And set the WebViewClient on your webView:</p> <pre><code>webView.setWebViewClient(new ProxyAuthWebViewClient("user", "password")); </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. 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.
 

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