android - 带有代理超时的 Android Webview
问题描述
我在将 Xamarin.Android 的 webview 与代理结合使用时遇到了问题。
设想:
Xamarin.Android 应用程序仅包含尝试加载“ http://google.com ”的 WebView。
当我在没有代理的 wifi 上时,它工作正常。
当我的 wifi 使用代理访问互联网时,它超时,wifi 连接的代理设置没有得到 webview 的尊重。使用平板电脑上的 Chrome 浏览器,它可以正常工作。
我尝试了所有我能找到的东西,但似乎没有任何效果......这些方法已经过时并且返回 null 或端口 -1。
Android.Net.Proxy.GetHost(this.ApplicationContext);
Android.Net.Proxy.GetPort(this.ApplicationContext);
Java.Lang.JavaSystem.GetProperty("http.proxyPort");
Java.Lang.JavaSystem.GetProperty("http.proxyHost");
所以我的问题是:如何让 webview 与 wifi 上设置的代理一起工作?
由于一个项目的问题,我被阻止了一周,非常感谢我能得到的每一个帮助。
代码:
// Inflate layout and find view
SetContentView(Resource.Layout.cas_login);
WebView wv = FindViewById<WebView>(Resource.Id.casWebView);
// Get URLs
string sessionId = UVM.GetJSessionId();
string apiUri = App.GetApiURI();
string websiteUrl = App.GetWebsiteUri();
string websiteRedirectUrl = websiteUrl + "api/myInfo/infos";
string requestUrl = $"{apiUri}login?requestUrl={websiteRedirectUrl}";
// Setup webView
wv.Settings.JavaScriptEnabled = true;
wv.Settings.BuiltInZoomControls = true;
wv.Settings.DisplayZoomControls = true;
wv.Settings.DomStorageEnabled = true;
wv.Settings.DatabaseEnabled = true;
wv.Settings.AllowContentAccess = true;
wv.Settings.SetAppCacheEnabled(true);
wv.Settings.UserAgentString = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
wv.Settings.MixedContentMode = MixedContentHandling.AlwaysAllow;
wv.SetWebViewClient(new CasWebViewClient(websiteRedirectUrl, ShowMainActivity));
//wv.SetWebChromeClient(new WebChromeClient());
WebView.SetWebContentsDebuggingEnabled(true);
WebView.EnablePlatformNotifications();
CookieManager.Instance.SetCookie(websiteUrl, sessionId);
// Load URL
_logger.LogMessage(LogLevel.Debug, "CasLogin.cs OnCreate", "Loading page: " + requestUrl);
wv.LoadUrl(requestUrl);
PS:如果我使用 WebChromeClient 它可以正常工作,它会打开 chrome 并且页面加载正常。
解决方案
推荐阅读
- android - Google Play 管理中心上的“获取商品详情”和“获取新用户”有什么区别?
- javafx - 如何在 NetBeans 12.1 上的 JavaFX 15 平台上安装 javadoc
- reactjs - 在路径“rowData.0.keyValues2”中检测到调度之间的状态突变。在农业网格中
- javascript - 扩展 HTMLButtonElement 的 WebComponent 没有调用 constructor() 和 connectedCallBack()
- javascript - 以动态方式单击所有子项的侦听器
- java - ROME 给我一个关于 DOCTYPE 的错误,但我的 XML 中没有 DOCTYPE 标记
- html - 无法在css中将元素移动到页面底部
- cypress - 无法登录 cypress 测试(500 错误)
- javascript - 如何使用 /a、/b 等更新 ref_no
- javascript - 如何在 vue.js 欢迎组件中使用引导程序而不是尾风 CSS