0

I have a webView where url is: https://uesr:user@test.move.com:443/test-mobile and when I want to load this page it is unaviable, where I delete authentication from page and delete user:user@ page work. How add authentication to webview to work with that url?

this is my webView:

formWebView.getSettings().setJavaScriptEnabled(true);
formWebView.loadUrl(url);
formWebView.getSettings().setBuiltInZoomControls(true);
edi233
  • 3,511
  • 13
  • 56
  • 97
  • Looks like HTTP Basic authentication. See if this helps: http://stackoverflow.com/questions/8935537/android-webview-with-https-connection-and-basic-auth-how-to-get-this-working – Ken Wolf Jul 04 '13 at 10:58
  • String usernameRandomPassword = "httpwatch:" + UUID.randomUUID().toString(); String authorization = "Basic " + Base64.encodeToString(usernameRandomPassword.getBytes("UTF-8"), Base64.NO_WRAP); where I must set my login and password? – edi233 Jul 04 '13 at 11:12
  • String usernameRandomPassword = "user:user"; – Ken Wolf Jul 04 '13 at 11:14
  • this solution doesn't work. Still get the same view – edi233 Jul 04 '13 at 11:23

2 Answers2

2

I resolve my problem by:

    formWebView.setWebViewClient(new WebViewClient() {
          @Override 
          public void onReceivedHttpAuthRequest(WebView view,
                                                HttpAuthHandler handler,
                                                String host,
                                                String realm){ 
            handler.proceed(loggedUser.getLogin(), loggedUser.getPass());
          } 

          public void onReceivedSslError(WebView view,
                                         SslErrorHandler handler,
                                         SslError error) {
            handler.proceed() ;
          }
        });
edi233
  • 3,511
  • 13
  • 56
  • 97
0

Write below code in your onCreate method.

webView.setWebViewClient(new MyWebViewClient());

private class MyWebViewClient extends WebViewClient 
{   

    public void onReceivedHttpAuthRequest(WebView view,
            HttpAuthHandler handler, String host, String realm) {

        handler.proceed("UserName", "Password");
    }

    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        if (dialog != null) {
            if (!dialog.isShowing()) {
                dialog.show();
            }
        }
    }

    public void onLoadResource(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onLoadResource(view, url);

    }

    public void onScaleChanged(WebView view, float oldScale, float newScale) {
        // TODO Auto-generated method stub
        super.onScaleChanged(view, oldScale, newScale);
    }

    public void onTooManyRedirects(WebView view, Message cancelMsg,
            Message continueMsg) {
        // TODO Auto-generated method stub
        super.onTooManyRedirects(view, cancelMsg, continueMsg);
    }

    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub




        return super.shouldOverrideUrlLoading(view, url);

    }

    public void doUpdateVisitedHistory(WebView view, String url,
            boolean isReload) {
        // TODO Auto-generated method stub
        super.doUpdateVisitedHistory(view, url, isReload);

    }

    public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl) {
        // TODO Auto-generated method stub
        super.onReceivedError(view, errorCode, description, failingUrl);
    }

    public void onPageFinished(WebView view, String url) {
        if (dialog != null) {

            dialog.dismiss();
        }
    }

}
Purushotham
  • 3,770
  • 29
  • 41
nilesh patel
  • 834
  • 1
  • 5
  • 10