【问题标题】:How to Make WebView Display SSL error Every Time Page is Reloaded?每次重新加载页面时如何使 WebView 显示 SSL 错误?
【发布时间】:2017-05-17 13:53:08
【问题描述】:

我的 webview 应用程序收到 SSL 错误。它会显示一条警告消息,询问是否加载网站。单击是按钮时,它会通过忽略 SSL 错误来加载网站。但是当我重新加载同一个网站时,它不会向我显示处理错误并直接加载网站的警告消息。

所以,我的问题是每次我重新加载网站时如何让 webview 向我显示处理 SSL 错误的警告消息?

我处理 ssl 错误的代码是``

                    if(error.getPrimaryError()==SslError.SSL_UNTRUSTED)
                    {

                        final Dialog sslalertdialog = new Dialog(browser.this);
                        sslalertdialog.setContentView(R.layout.sslerroralert);
                        sslalertdialog.show();
                        TextView sslalertmessage, sslalerttitle;
                        Button yes,no;
                        sslalertmessage= (TextView) sslalertdialog.findViewById(R.id.sslerrormessage);
                        sslalerttitle= (TextView) sslalertdialog.findViewById(R.id.sslerrorTitle);
                        String  message="The Website Security Certificate is Not Trusted." +
                                "One possible cause of this error is that a self-signed certificate is installed on the Website's server. " +
                                "Self-signed certificates aren't trusted by browsers because they are generated by Website's server, not by an accredited Certificate Authority (CA)." +
                                "Another cause of the error is that Someone is trying to intercept your communication." +
                                "You Should not Proceed,if you have never seen this error message for this Website before." +
                                "And if you want to proceed ,plz donot provide any sensitive Infomation to the site (like Credit Card Details " +
                                "Do you want to proceed anyways ?";
                        sslalerttitle.setText("The Website Cannot be Trusted!");
                        sslalertmessage.setText(message);
                        no=(Button) sslalertdialog.findViewById(R.id.NOBUTTON);
                        yes=(Button) sslalertdialog.findViewById(R.id.YES_BUTTON);
                        no.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                sslalertdialog.dismiss();
                                handler.cancel();
                            }
                        });
                        yes.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                sslalertdialog.dismiss();
                                handler.proceed();

                                padlock.setImageDrawable(getDrawable(R.drawable.ic_warning_red_400_24dp));

                            }
                        });

【问题讨论】:

  • 那个有什么消息吗?我遇到了同样的问题,每次都需要显示一个对话框。

标签: android ssl webview


【解决方案1】:

您可以使用 WebView 的 clearSslPreferences() 函数,例如:

webView.clearSslPreferences()

它会清除您对这个 WebView 对象的决定,并且您可能会再次收到警告消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 2014-06-10
    • 1970-01-01
    • 2012-06-21
    • 2018-01-23
    • 2021-11-13
    • 2015-06-17
    相关资源
    最近更新 更多