我正在尝试进行基本身份验证以查看受保护的URL.我想访问受保护的URL,如下所示:
http://api.test.com/userinfo/vid?=1234
Run Code Online (Sandbox Code Playgroud)
所以我使用WebView执行以下操作:
mWebView.setHttpAuthUsernamePassword("api.test.com", "", "me@test.com", "mypassword");
mWebView.loadUrl("http://api.test.com/userinfo/user?uid=53461");
Run Code Online (Sandbox Code Playgroud)
但验证似乎不起作用,我只是得到一个输出错误页面.我在这里正确使用WebView方法吗?
更新:尝试卷曲:
curl -u me@test.com:mypassword http://api.test.com/userinfo/user?uid=53461
Run Code Online (Sandbox Code Playgroud)
它拉页面很好.我尝试了主机参数的每一个组合,api的所有者不知道我的意思是什么'领域'虽然(我也不知道) - 我可以给他们什么信息来帮助这个?
谢谢
dpa*_*nas 99
另一种选择是使用WebViewClient;
webview.setWebViewClient(new MyWebViewClient ());
private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
handler.proceed("me@test.com", "mypassword");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 8
webview.setWebViewClient(new WebViewClient () {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
handler.proceed("login", "pass");
}
});
Run Code Online (Sandbox Code Playgroud)
小智 7
WebView的默认行为是放弃所有身份验证请求.即使setHttpAuthUsernamePassword.
您必须设置WebViewClient并覆盖方法onReceivedHttpAuthRequest
| 归档时间: |
|
| 查看次数: |
31152 次 |
| 最近记录: |