Job Smith Job Smith - 2 months ago 15x
HTTP Question

Handling HTTP basic authentication using Android webview

I am using a webview to load a webpage which requires basic HTTP authentication. I have done some Google search and I knew it can be done by using a

and over-writing

like this

webView.setWebViewClient(new WebViewClient() {

public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
// TODO Auto-generated method stub

handler.proceed(username, password); //question is here,let user input these.

what I have already tried is I use a Login activity to get the users's input and pass the parameter back to this webview activity.

But is this the best way of doing it?


try this method with HttPget and HttpPost

        CredentialsProvider credProvider = new BasicCredentialsProvider();

        credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, 

        AuthScope.ANY_PORT,AuthScope.ANY_REALM),  new UsernamePasswordCredentials("admin", 

        Log.w("SENCIDE", "Execute HTTP Get Request");
        HttpResponse response = httpclient.execute(httpget);

This is sample code for Authentication code in Httpget . You can try by this w't you want...