gpt4 book ai didi

android - WebView - onReceivedHttpAuthRequest 永不停止

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:22:24 24 4
gpt4 key购买 nike

我在 Android webview 应用程序中陷入死循环,应用程序在 onReceivedHttpAuthRequest 函数上被阻止。

mWeb.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
mProgressBar.setVisibility(View.GONE);
}

@Override
public void onReceivedHttpAuthRequest(WebView view,HttpAuthHandler handler, String host, String realm) {
if (isAdded())
handler.proceed(getResources().getString(R.string.username), getResources().getString(R.string.pass));
}

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
mWeb.loadUrl(mUrl);

最佳答案

关于 Activity



mWebView.LoadUrl(url);
await Task.Delay(10000);
if (!mWebView.IsShown | cliente.ErroReportado)
{
Toast t = Toast.MakeText(Android.App.Application.Context, "Erro ao acessar o servidor, verifique conexão, usuário e senha e tente novamente!", ToastLength.Long);
t.SetGravity(GravityFlags.Center, 0, 0);
t.Show();
OnCreate(null);
}
}

在 WebViewClient 上

<p></p>

class ViewClient : WebViewClient
{
MainActivity _activity;

public int iTentativasLogin { get; private set; }
public bool ErroReportado { get; private set; }


public ViewClient(MainActivity activity)
{
_activity = activity;
}


public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm)
{
Toast t ;
if (Usuario.Length == 0 | Senha.Length == 0)
{
t = Toast.MakeText(Android.App.Application.Context, "Usuário ou senha não preenchidos", ToastLength.Long);
t.SetGravity(GravityFlags.Center, 0, 0);
t.Show();
handler.Cancel();
ErroReportado = true;
}
else
{
iTentativasLogin++;

if (iTentativasLogin < 4)
{
handler.Proceed(Usuario, Senha);
}
else
{
t = Toast.MakeText(Android.App.Application.Context, "Usuário ou senha incorretos", ToastLength.Long);
t.SetGravity(GravityFlags.Center, 0, 0);
t.Show();
handler.Cancel();
ErroReportado = true;
}

}
}
}

关于android - WebView - onReceivedHttpAuthRequest 永不停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41461787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com