Android WebView blocks redirect from https to http

前端 未结 4 2062
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 19:30

I have a solution where my Android WebView needs to first open a https url, then it will be redirected to a http url (it might be trying a http POST from the https site). Th

4条回答
  •  孤独总比滥情好
    2020-12-28 19:53

    Its worked for me

     AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.webView.getContext());
      AlertDialog alertDialog = builder.create();
      String message = "Certificate error.";
      switch (error.getPrimaryError()) {
         case SslError.SSL_UNTRUSTED:
            message = "The certificate authority is not trusted.";
            break;
         case SslError.SSL_EXPIRED:
            message = "The certificate has expired.";
            break;
         case SslError.SSL_IDMISMATCH:
            message = "The certificate Hostname mismatch.";
            break;
         case SslError.SSL_NOTYETVALID:
            message = "The certificate is not yet valid.";
            break;
      }
      message += " Do you want to continue anyway?";
      alertDialog.setTitle("SSL Certificate Error");
      alertDialog.setMessage(message);
      alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
    
         public void onClick(DialogInterface dialog, int which) {
            Log.d("CHECK", "Button ok pressed");
            // Ignore SSL certificate errors
            handler.proceed();
         }
      });
      alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
    
         public void onClick(DialogInterface dialog, int which) {
            Log.d("CHECK", "Button cancel pressed");
            handler.cancel();
         }
      });
      alertDialog.show();
    

提交回复
热议问题