当前位置: 首页>>代码示例>>C#>>正文


C# Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef方法代码示例

本文整理汇总了C#中Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef方法的典型用法代码示例。如果您正苦于以下问题:C# Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef方法的具体用法?C# Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef怎么用?C# Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interop.WinHttp.SafeWinHttpHandle的用法示例。


在下文中一共展示了Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WinHttpRequestStream

 internal WinHttpRequestStream(SafeWinHttpHandle requestHandle, bool chunkedMode)
 {
     bool ignore = false;
     requestHandle.DangerousAddRef(ref ignore);
     _requestHandle = requestHandle;
     _chunkedMode = chunkedMode;
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:7,代码来源:WinHttpRequestStream.cs

示例2: WinHttpResponseStream

 internal WinHttpResponseStream(
     SafeWinHttpHandle sessionHandle,
     SafeWinHttpHandle connectHandle,
     SafeWinHttpHandle requestHandle)
 {
     // While we only use the requestHandle to do actual reads of the response body,
     // we need to keep the parent handles (connection, session) alive as well.
     bool ignore = false;
     sessionHandle.DangerousAddRef(ref ignore);
     connectHandle.DangerousAddRef(ref ignore);
     requestHandle.DangerousAddRef(ref ignore);
     _sessionHandle = sessionHandle;
     _connectHandle = connectHandle;
     _requestHandle = requestHandle;
 }
开发者ID:peterblazejewicz,项目名称:corefx,代码行数:15,代码来源:WinHttpResponseStream.cs

示例3: EnsureSessionHandleExists

        private void EnsureSessionHandleExists(RequestState state)
        {
            bool ignore = false;

            if (_sessionHandle == null)
            {
                lock (_lockObject)
                {
                    if (_sessionHandle == null)
                    {
                        uint accessType;

                        // If a custom proxy is specified and it is really the system web proxy
                        // (initial WebRequest.DefaultWebProxy) then we need to update the settings
                        // since that object is only a sentinel.
                        if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy)
                        {
                            Debug.Assert(state.Proxy != null);
                            try
                            {
                                state.Proxy.GetProxy(state.RequestMessage.RequestUri);
                            }
                            catch (PlatformNotSupportedException)
                            {
                                // This is the system web proxy.
                                state.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy;
                                state.Proxy = null;
                            }
                        }

                        if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.DoNotUseProxy ||
                            state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy)
                        {
                            // Either no proxy at all or a custom IWebProxy proxy is specified.
                            // For a custom IWebProxy, we'll need to calculate and set the proxy
                            // on a per request handle basis using the request Uri.  For now,
                            // we set the session handle to have no proxy.
                            accessType = Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY;
                        }
                        else if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseWinHttpProxy)
                        {
                            // Use WinHTTP per-machine proxy settings which are set using the "netsh winhttp" command.
                            accessType = Interop.WinHttp.WINHTTP_ACCESS_TYPE_DEFAULT_PROXY;
                        }
                        else
                        {
                            // Use WinInet per-user proxy settings.
                            accessType = Interop.WinHttp.WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY;
                        }

                        _sessionHandle = Interop.WinHttp.WinHttpOpen(
                            IntPtr.Zero,
                            accessType,
                            Interop.WinHttp.WINHTTP_NO_PROXY_NAME,
                            Interop.WinHttp.WINHTTP_NO_PROXY_BYPASS,
                            0);
                        if (!_sessionHandle.IsInvalid)
                        {
                            _sessionHandle.DangerousAddRef(ref ignore);

                            return;
                        }

                        int lastError = Marshal.GetLastWin32Error();
                        if (lastError != Interop.WinHttp.ERROR_INVALID_PARAMETER)
                        {
                            throw new HttpRequestException(
                                SR.net_http_client_execution_error,
                                WinHttpException.CreateExceptionUsingError(lastError));
                        }

                        // We must be running on a platform earlier than Win8.1/Win2K12R2 which doesn't support
                        // WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY.  So, we'll need to read the Wininet style proxy
                        // settings ourself using our WinInetProxyHelper object.
                        _proxyHelper = new WinInetProxyHelper();
                        _sessionHandle = Interop.WinHttp.WinHttpOpen(
                            IntPtr.Zero,
                            _proxyHelper.ManualSettingsOnly ? Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY : Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY,
                            _proxyHelper.ManualSettingsOnly ? _proxyHelper.Proxy : Interop.WinHttp.WINHTTP_NO_PROXY_NAME,
                            _proxyHelper.ManualSettingsOnly ? _proxyHelper.ProxyBypass : Interop.WinHttp.WINHTTP_NO_PROXY_BYPASS,
                            0);
                        if (_sessionHandle.IsInvalid)
                        {
                            throw new HttpRequestException(
                                SR.net_http_client_execution_error,
                                WinHttpException.CreateExceptionUsingLastError());
                        }

                        _sessionHandle.DangerousAddRef(ref ignore);
                    }
                }
            }
        }
开发者ID:Atomosk,项目名称:corefx,代码行数:93,代码来源:WinHttpHandler.cs


注:本文中的Interop.WinHttp.SafeWinHttpHandle.DangerousAddRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。