我通过url加载我的整个网站。我需要一种方法来保存用户名和密码的罪过,我没有使用任何代码在xamarin项目。我不知道该怎么做,我对这个领域还比较陌生。
发布于 2021-07-07 16:40:44
WebViewClient类有一个回调方法OnReceivedHttpAuthRequest,当服务器需要用户名和密码时,WebView将调用该方法。此方法的参数之一是HttpAuthHandler接口。您可以通过调用此处理程序上的方法来控制授权请求。
因此,解决方案是创建一个覆盖OnReceivedHttpAuthRequest的WebViewClient子类,并在HttpAuthHandler上调用适当的方法。然后将您的WebView设置为拥有此子类的一个实例。
下面是Xamarin文档的链接:OnReceivedHttpAuthRequest - Xamarin。
var client = new MyWebViewClient();
WebView web = FindViewById<WebView>(Resource.Id.webView1);
web.SetWebViewClient(client);
class MyWebViewClient : WebViewClient {
public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) {
handler.Proceed(username, password);
}
}https://stackoverflow.com/questions/68278885
复制相似问题