Using WebView setHttpAuthUsernamePassword?
I'm trying to do basic authentication to view a protected url. I want to access the protected url which looks like this:
http://api.test.com/userinfo/vid?=1234
So I do the following with a WebView:
mWebView.setHttpAuthUsernamePassword("api.test.com", "", "[email protected]", "mypassword");
mWebView.loadUrl("http://api.test.com/userinfo/user?uid=53461");
but the authentication doesn't seem to work, I'm just getting an output error page. Am I using the WebView method correctly here?
Update: Trying with curl:
curl -u [email protected]:mypassword http://api.test.com/userinfo/user?uid=53461
and it pulls the page fine. I tried every combination of the host parameter, the owners of the api don't know what I mean by 'realm' though (and neither do I) - what info could I give them to help this along?
Thanks
Another option is to use a WebViewClient;
webview.setWebViewClient(new MyWebViewClient ());
private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
handler.proceed("[email protected]", "mypassword");
}
}
webview.setWebViewClient(new WebViewClient () {
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
handler.proceed("login", "pass");
}
});
The default behavior of a WebView is to discard all authentication requests. Even if setHttpAuthUsernamePassword.
You have to set a WebViewClient and Override the method onReceivedHttpAuthRequest