android 在WebView上为API 26设置代理

v09wglhw  于 2023-08-01  发布在  Android
关注(0)|答案(2)|浏览(269)

首先,我已经阅读了所有与我的问题类似的问题的答案。但没有一个解决方案帮助了我。
这是我的Webview代码

mWebView.loadUrl(siteUrl);       
mWebView.getSettings().setUserAgentString(ua);      
mWebView.getSettings().setJavaScriptEnabled(true);      
mWebView.getSettings().setDomStorageEnabled(true);      
mWebView.setWebViewClient(new mWebViewClient());

字符串
我尝试使用这个类https://gist.github.com/madeye/2297083
我用这段代码来设置代理

ProxySettings.setProxy(getApplicationContext(), "x.x.x.x", 8080);


我还测试了这个类https://gist.github.com/WanghongLin/50032a4d3933960454a7
和/或

WebViewHttpProxy.setProxy(mWebView,"x.x.x.x",8080);


但都不管用。当我运行应用程序时,代理没有应用

mspsb9vt

mspsb9vt1#

非常容易在您的Android Webview应用程序上设置代理
compile 'android.webkit:webkit:1.3.0' setProxy();在你的webview URL加载之前加载。

private void init() {
    wv = findViewById(R.id.wv);
    WebSettings webSettings = wv.getSettings();
    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm){
            
            handler.proceed("userName", "password");
        }
    });
    setProxy();
    wv.loadUrl("https://www.google.com");
}

private void setProxy() {
        ProxyConfig proxyConfig = new ProxyConfig.Builder()
                .addProxyRule("123.123.123.123:1234")
                .addDirect().build();
        ProxyController.getInstance().setProxyOverride(proxyConfig, new Executor() {
            @Override
            public void execute(Runnable command) {
                //do nothing
            }
        }, new Runnable() {
            @Override
            public void run() {
                
            }
        });
    }

字符串
好好享受

rjee0c15

rjee0c152#

我不确定,但我觉得你在加载URL(webView.loadUrl)后设置代理,所以它可能不适用

相关问题