WebViewClient
クラスは、サーバーがユーザー名とパスワードを要求したときにWebView
によって呼び出されるコールバックメソッドOnReceivedHttpAuthRequest
を持っています。このメソッドのパラメータの1つは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);
}
}