Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Basic Authentication in WebView

Tags:

I've created an application which loads a WebView. In order to login, the website requires basic authentication. When i try to access the website via the default browser, I get a pop up box prompting me to enter my user name and password.

If I try to access the website via my application, I get error 401 and no pop up. I was wondering if someone could help me out?

like image 761
Kyle Avatar asked Nov 18 '10 23:11

Kyle


People also ask

What is basic authentication in web?

HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID and password) from a client. The client passes the authentication information to the server in an Authorization header.

Can we save login data in Android WebView?

Saving passwords in WebView will not be supported in future versions. Retrieves HTTP authentication credentials for a given host and realm from the WebViewDatabase instance.

Do cookies work in WebView?

By default this is set to true and the WebView accepts cookies.


1 Answers

I reckon a more elegant solution than the one Patrick describes would be to use the onReceivedHttpAuthRequest method of WebViewClient as described here: http://www.mail-archive.com/[email protected]/msg30468.html

@Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {     handler.proceed("username", "password"); } 
like image 171
Saad Farooq Avatar answered Oct 06 '22 01:10

Saad Farooq