/// <summary>
        ///     Проставить опции проверки сертификатов сервера
        /// </summary>
        /// <param name="hRequest">
        ///     Указатель на HTTPS-запрос
        /// </param>
        private static void SetCertificateCheckOptions(IntPtr hRequest)
        {
            uint flagsLen = sizeof(uint);
            var  flags    = new WinInet.InternetOptionSecurityFlags();
            var  pFlags   = Marshal.AllocHGlobal(Marshal.SizeOf(flags));

            Marshal.StructureToPtr(flags, pFlags, true);
            var queryOption = WinInet.InternetQueryOptionW(hRequest, WinInet.INTERNET_OPTION_SECURITY_FLAGS, pFlags, ref flagsLen);

            flags = (WinInet.InternetOptionSecurityFlags)
                    Marshal.PtrToStructure(pFlags, typeof(WinInet.InternetOptionSecurityFlags));
            Marshal.FreeHGlobal(pFlags);
            if (!queryOption)
            {
                ThrowWinInetLastException("InternetQueryOption + INTERNET_OPTION_SECURITY_FLAGS");
            }

            flags.value |= WinInet.SECURITY_FLAG_IGNORE_REVOCATION;
            flags.value |= WinInet.SECURITY_FLAG_IGNORE_UNKNOWN_CA;

            pFlags = Marshal.AllocHGlobal(Marshal.SizeOf(flags));
            Marshal.StructureToPtr(flags, pFlags, true);
            var certRevSet = WinInet.InternetSetOptionW(hRequest, WinInet.INTERNET_OPTION_SECURITY_FLAGS, pFlags, flagsLen);

            Marshal.FreeHGlobal(pFlags);
            if (!certRevSet)
            {
                ThrowWinInetLastException("InternetSetOption + INTERNET_OPTION_SECURITY_FLAGS");
            }
        }
        /// <summary>
        ///     Проставить опции проверки сертификатов сервера
        /// </summary>
        /// <param name="hRequest">
        ///     Указатель на HTTPS-запрос
        /// </param>
        private static void SetCertificateCheckOptions(IntPtr hRequest)
        {
            uint flagsLen = sizeof(uint);
            var flags = new WinInet.InternetOptionSecurityFlags();
            var pFlags = Marshal.AllocHGlobal(Marshal.SizeOf(flags));
            Marshal.StructureToPtr(flags, pFlags, true);
            var queryOption = WinInet.InternetQueryOptionW(hRequest, WinInet.INTERNET_OPTION_SECURITY_FLAGS, pFlags, ref flagsLen);
            flags = (WinInet.InternetOptionSecurityFlags)
                Marshal.PtrToStructure(pFlags, typeof(WinInet.InternetOptionSecurityFlags));
            Marshal.FreeHGlobal(pFlags);
            if (!queryOption)
            {
                ThrowWinInetLastException("InternetQueryOption + INTERNET_OPTION_SECURITY_FLAGS");
            }

            flags.value |= WinInet.SECURITY_FLAG_IGNORE_REVOCATION;
            flags.value |= WinInet.SECURITY_FLAG_IGNORE_UNKNOWN_CA;

            pFlags = Marshal.AllocHGlobal(Marshal.SizeOf(flags));
            Marshal.StructureToPtr(flags, pFlags, true);
            var certRevSet = WinInet.InternetSetOptionW(hRequest, WinInet.INTERNET_OPTION_SECURITY_FLAGS, pFlags, flagsLen);
            Marshal.FreeHGlobal(pFlags);
            if (!certRevSet)
            {
                ThrowWinInetLastException("InternetSetOption + INTERNET_OPTION_SECURITY_FLAGS");
            }
        }