WebView.setHttpAuthUsernamePassword() 不起作用?
我正在开发 Android 应用程序的一部分,需要使用 WebView 打开受密码保护的网站。我使用 SharedPreferences 提供用户首次登录应用程序时的用户名和密码。我已经测试了它返回的凭据,所以我知道这些是正确的。当我在模拟器中运行它时,该网站说我未经授权(即使我是)。这是代码:
setContentView(R.layout.browser);
WebView browser = (WebView) findViewById(R.id.browser);
browser.getSettings().setJavaScriptEnabled(true);
SharedPreferences credentials = getSharedPreferences("credentials", 0);
browser.setHttpAuthUsernamePassword("example.com", "", credentials.getString("username", ""), credentials.getString("password", ""));
browser.loadUrl("http://example.com");
那么有人知道为什么这不能验证我的身份吗?我放置“”的领域字符串实际上应该是什么吗?
I am developing part of an Android application that needs to use a WebView to open a password protected site. I am using SharedPreferences to provide the username and password from when the user logs in the app for the first time. I've tested the credentials it's returning, so I know that those are correct. When I run this in the emulator, the site says that I'm unauthorized (even though I am). Here's the code:
setContentView(R.layout.browser);
WebView browser = (WebView) findViewById(R.id.browser);
browser.getSettings().setJavaScriptEnabled(true);
SharedPreferences credentials = getSharedPreferences("credentials", 0);
browser.setHttpAuthUsernamePassword("example.com", "", credentials.getString("username", ""), credentials.getString("password", ""));
browser.loadUrl("http://example.com");
So does anyone know why this wouldn't be authenticating me? Should the realm string that I put "" for actually be something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以使用这个:
You can use this:
如果站点使用 NTLM 身份验证,它将无法工作。 Android 本身不支持 NTLM Auth。 Fennec(firefox mobile)是我见过的唯一支持它的 Android 浏览器,但它仍处于 alpha 阶段。
if the site is using NTLM auth it won't work. Android does not natively support NTLM Auth. Fennec (firefox mobile) is the only android browser i've seen that supports it, but its still in alpha.
Android 声称现在支持 NTLM。我不知道这是
WebView
的一部分还是只是浏览器的一部分。https://code.google.com/p/android/issues/detail ?id=4962
Android claims to support NTLM now. I don't know if that is part of the
WebView
or just the browser.https://code.google.com/p/android/issues/detail?id=4962