Reputation: 263
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 WebClientView
and over-writing onReceivedHttpAuthRequest
.
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?
Upvotes: 1
Views: 2184
Reputation: 1682
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",
"guest"));
httpclient.setCredentialsProvider(credProvider);
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...
Upvotes: 1