From ec901bfd42ee3f46f5b5269e2a838da1ef111455 Mon Sep 17 00:00:00 2001
From: client_Hale <339726288@qq.com>
Date: 星期二, 25 九月 2018 10:52:40 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.0.87:10010/r/snxxz_scripts

---
 System/HttpRequest/HttpBehaviour.cs |   91 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/System/HttpRequest/HttpBehaviour.cs b/System/HttpRequest/HttpBehaviour.cs
index d914d34..6a45c70 100644
--- a/System/HttpRequest/HttpBehaviour.cs
+++ b/System/HttpRequest/HttpBehaviour.cs
@@ -1,11 +1,13 @@
-锘縰sing System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using System;
+锘縰sing System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System;
 using System.Net;
-using System.Text;
-using System.IO;
-
+using System.Text;
+using System.IO;
+using System.Net.Security;
+using System.Security.Cryptography.X509Certificates;
+
 public class HttpBehaviour : MonoBehaviour
 {
 
@@ -24,6 +26,11 @@
     bool ok = false;
     string message = string.Empty;
 
+    static HttpBehaviour()
+    {
+        ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;
+    }
+
     public static void Create(string _url, string _method, string _content, string _contentType, int _retry = 3, Action<bool, string> _result = null)
     {
         var carrier = new GameObject();
@@ -33,7 +40,7 @@
         behaviour.Begin(_url, _method, _content, _contentType, _retry, _result);
     }
 
-    public void Begin(string _url, string _method, string _content, string _contentType, int _retry = 3, Action<bool, string> _result = null)
+    void Begin(string _url, string _method, string _content, string _contentType, int _retry = 3, Action<bool, string> _result = null)
     {
         this.url = _url;
         this.method = _method;
@@ -107,6 +114,51 @@
 
     }
 
+    private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
+    {
+        if (sslPolicyErrors == SslPolicyErrors.None)
+        {
+            return true;
+        }
+
+        var acceptCertificate = true;
+        if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)
+        {
+            acceptCertificate = false;
+        }
+        else
+        {
+            if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)
+            {
+                acceptCertificate = false;
+            }
+
+            if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)
+            {
+                foreach (X509ChainStatus item in chain.ChainStatus)
+                {
+                    if (item.Status != X509ChainStatusFlags.RevocationStatusUnknown &&
+                        item.Status != X509ChainStatusFlags.OfflineRevocation)
+                    {
+                        break;
+                    }
+
+                    if (item.Status != X509ChainStatusFlags.NoError)
+                    {
+                        acceptCertificate = false;
+                    }
+                }
+            }
+        }
+
+        if (acceptCertificate == false)
+        {
+            acceptCertificate = true;
+        }
+
+        return acceptCertificate;
+    }
+
     void Update()
     {
         if (Time.time > timeOut && !getResult)
@@ -122,14 +174,25 @@
 
         if (getResult)
         {
-            if (callBack != null)
+            try
             {
-                callBack(ok, message);
-                callBack = null;
                 DebugEx.LogFormat("Http 鏁版嵁閫氫俊 {0},璇锋眰鏁版嵁缁撴灉锛歿1},鍐呭锛歿2}", this.url, ok, message);
+
+                if (callBack != null)
+                {
+                    callBack(ok, message);
+                }
+            }
+            catch (Exception ex)
+            {
+                Debug.Log(ex);
+            }
+            finally
+            {
+                callBack = null;
+                Destroy(this.gameObject);
             }
 
-            Destroy(this.gameObject);
         }
     }
 
@@ -194,5 +257,5 @@
         }
     }
 
-
-}
+
+}

--
Gitblit v1.8.0