问题描述
我正在研究一个项目,该项目通过android应用程序中的WebView
来对网站进行身份验证.我已经对该问题进行了很多研究,共识是使用onReceivedHttpAuthRequest
方法.但是,如果使用诸如webview.loadUrl("https://github.com/login");
之类的命令,则无论在页面加载还是登录时,都不会在Catlog中收到调试消息. AuthRequest
永远不会通过?
I am working on a project to authenticate to a website via a WebView
in an android app. I have researched the issue quite a bit, the consensus is to use the onReceivedHttpAuthRequest
Method. However if I use a command such as webview.loadUrl("https://github.com/login");
I never get debug message in the Catlog either when the page loads or when I login. Is there a reason why the AuthRequest
would never come through?
@Override
public void onReceivedHttpAuthRequest(WebView view,HttpAuthHandler handler, String host, String realm) {
handler.proceed("me@test.com", "mypassword");
Log.d("request","received")
}
推荐答案
身份验证有不同的类型.当传入HTTP身份验证请求(基本/摘要身份验证)时,将调用onReceivedHttpAuthRequest().您在转到 https://github.com/login 时给出的示例,该页面不是使用这种身份验证.
There are different types of authentication. onReceivedHttpAuthRequest() is called when an HTTP authentication request comes in (Basic/Digest authentication). The example that you gave for when you go to https://github.com/login this is not a page that uses this type of authentication.
当浏览器看到这种身份验证请求时,通常会显示一个登录对话框,提示用户输入用户名和密码.
When the browser sees this type of authentication request it typically displays a login dialog box prompting the user for a username and password.
这篇关于Android Webview URL身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!