private bool WinHttpGetProxyForUrl(string destination, ref UnsafeNclNativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out string proxyListString)
 {
     proxyListString = null;
     bool flag = false;
     UnsafeNclNativeMethods.WinHttp.WINHTTP_PROXY_INFO proxyInfo = new UnsafeNclNativeMethods.WinHttp.WINHTTP_PROXY_INFO();
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         flag = UnsafeNclNativeMethods.WinHttp.WinHttpGetProxyForUrl(this.session, destination, ref autoProxyOptions, out proxyInfo);
         if (flag)
         {
             proxyListString = Marshal.PtrToStringUni(proxyInfo.Proxy);
         }
     }
     finally
     {
         Marshal.FreeHGlobal(proxyInfo.Proxy);
         Marshal.FreeHGlobal(proxyInfo.ProxyBypass);
     }
     return flag;
 }
コード例 #2
0
        private bool WinHttpGetProxyForUrl(string destination,
            ref UnsafeNclNativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
            out string proxyListString)
        {
            proxyListString = null;

            bool success = false;
            UnsafeNclNativeMethods.WinHttp.WINHTTP_PROXY_INFO proxyInfo =
                new UnsafeNclNativeMethods.WinHttp.WINHTTP_PROXY_INFO();

            // Make sure the strings get cleaned up in a CER (thus unexpected exceptions, like
            // ThreadAbortException will not interrupt the execution of the finally block, and we'll not
            // leak resources).
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                success = UnsafeNclNativeMethods.WinHttp.WinHttpGetProxyForUrl(session,
                    destination, ref autoProxyOptions, out proxyInfo);

                if (success)
                {
                    proxyListString = Marshal.PtrToStringUni(proxyInfo.Proxy);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(proxyInfo.Proxy);
                Marshal.FreeHGlobal(proxyInfo.ProxyBypass);
            }

            return success;
        }