| | |
| | | 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();
|
| | |
| | | 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;
|
| | |
| | | request.ReadWriteTimeout = 2000;
|
| | | request.Proxy = null;
|
| | | request.KeepAlive = false;
|
| | | ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | |
| | | 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;
|
| | | return true;
|
| | | }
|
| | |
|
| | | var acceptCertificate = true;
|
| | | if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)
|
| | | {
|
| | | acceptCertificate = false;
|
| | | }
|
| | | else
|
| | | {
|
| | | if ((sslPolicyErrors &
|
| | | SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)
|
| | | if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)
|
| | | {
|
| | | _acceptCertificate = false;
|
| | | acceptCertificate = false;
|
| | | }
|
| | |
|
| | | if ((sslPolicyErrors &
|
| | | SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)
|
| | | 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;
|
| | | acceptCertificate = false;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (_acceptCertificate == false)
|
| | | if (acceptCertificate == false)
|
| | | {
|
| | | _acceptCertificate = true;
|
| | | acceptCertificate = true;
|
| | | }
|
| | |
|
| | | return _acceptCertificate;
|
| | | return acceptCertificate;
|
| | | }
|
| | |
|
| | | void Update()
|
| | | {
|
| | | if (Time.time > timeOut && !getResult)
|