瀏覽代碼

增加双向认证的webViewClient

Pq 10 月之前
父節點
當前提交
a8ac4abbef
共有 1 個文件被更改,包括 33 次插入0 次删除
  1. 33 0
      BaseLibrary/src/main/java/com/cooleshow/base/widgets/HttpsServerCertWebViewClient.java

+ 33 - 0
BaseLibrary/src/main/java/com/cooleshow/base/widgets/HttpsServerCertWebViewClient.java

@@ -0,0 +1,33 @@
+package com.cooleshow.base.widgets;
+
+import android.net.http.SslError;
+import android.webkit.ClientCertRequest;
+import android.webkit.SslErrorHandler;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import com.cooleshow.base.data.auth.Https;
+import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.Utils;
+
+
+/**
+ * Author by pq, Date on 2024/5/28.
+ */
+public class HttpsServerCertWebViewClient extends WebViewClient {
+    @Override
+    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
+        LOG.i("onReceivedSslError:");
+        if (error != null) {
+            LOG.i("onReceivedSslError:" + error.getUrl());
+            LOG.i("onReceivedSslError:" + error.getPrimaryError());
+            LOG.i("onReceivedSslError:" + error.getCertificate());
+        }
+    }
+
+    @Override
+    public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
+        LOG.i("onReceivedClientCertRequest");
+        Https.proceed(Utils.getApp(), request);
+    }
+}