Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WebView setHttpAuthUsernamePassword?

Tags:

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

like image 217
user246114 Avatar asked Apr 06 '10 13:04

user246114


2 Answers

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");  } } 
like image 188
dparnas Avatar answered Oct 15 '22 20:10

dparnas


webview.setWebViewClient(new WebViewClient () {      public void onReceivedHttpAuthRequest(WebView view,             HttpAuthHandler handler, String host, String realm) {          handler.proceed("login", "pass");     } }); 
like image 24
Dmitry Avatar answered Oct 15 '22 19:10

Dmitry