SHARE
TWEET

TIME FROM INTERNET

a guest Aug 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     void Awake()
  3.     {
  4.         if (Application.internetReachability != NetworkReachability.NotReachable)
  5.         {
  6.             Debug.Log(GetNistTime());
  7.         }
  8.     }
  9.     public DateTime GetNistTime()
  10.     {
  11.         ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
  12.         var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
  13.         var response = myHttpWebRequest.GetResponse();
  14.         string todaysDates = response.Headers["date"];
  15.         return DateTime.ParseExact(todaysDates,
  16.                                    "ddd, dd MMM yyyy HH:mm:ss 'GMT'",
  17.                                    CultureInfo.InvariantCulture.DateTimeFormat,
  18.                                    DateTimeStyles.AssumeUniversal);
  19.     }
  20.     public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  21.     {
  22.         bool isOk = true;
  23.         // If there are errors in the certificate chain, look at each error to determine the cause.
  24.         if (sslPolicyErrors != SslPolicyErrors.None)
  25.         {
  26.             for (int i = 0; i < chain.ChainStatus.Length; i++)
  27.             {
  28.                 if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown)
  29.                 {
  30.                     chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain;
  31.                     chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
  32.                     chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
  33.                     chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
  34.                     bool chainIsValid = chain.Build((X509Certificate2)certificate);
  35.                     if (!chainIsValid)
  36.                     {
  37.                         isOk = false;
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.         return isOk;
  43.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top