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


C# WinHttp.SafeWinHttpHandle类代码示例

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


Interop.WinHttp.SafeWinHttpHandle类属于命名空间,在下文中一共展示了Interop.WinHttp.SafeWinHttpHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: WinHttpConnect

 public static SafeWinHttpHandle WinHttpConnect(
     SafeWinHttpHandle sessionHandle,
     string serverName,
     ushort serverPort,
     uint reserved)
 {
     return new FakeSafeWinHttpHandle(true);
 }
开发者ID:peterblazejewicz,项目名称:corefx,代码行数:8,代码来源:FakeInterop.cs

示例3: SetChannelBinding

        internal void SetChannelBinding(SafeWinHttpHandle requestHandle)
        {
            var channelBinding = new WinHttpChannelBinding(requestHandle);

            if (channelBinding.IsInvalid)
            {
                channelBinding.Dispose();
            }
            else
            {
                _channelBinding = channelBinding;
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:WinHttpTransportContext.cs

示例4: 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

示例5: WinHttpChannelBinding

        internal WinHttpChannelBinding(SafeWinHttpHandle requestHandle)
        {
            IntPtr data = IntPtr.Zero;
            uint dataSize = 0;

            if (!Interop.WinHttp.WinHttpQueryOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_SERVER_CBT, null, ref dataSize))
            {
                if (Marshal.GetLastWin32Error() == Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER)
                {
                    data = Marshal.AllocHGlobal((int)dataSize);

                    if (Interop.WinHttp.WinHttpQueryOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_SERVER_CBT, data, ref dataSize))
                    {
                        SetHandle(data);
                        _size = (int)dataSize;
                    }
                    else
                    {
                        Marshal.FreeHGlobal(data);
                    }
                }
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:23,代码来源:WinHttpChannelBinding.cs

示例6: SetNoClientCertificate

 private static void SetNoClientCertificate(SafeWinHttpHandle requestHandle)
 {
     SetWinHttpOption(
         requestHandle,
         Interop.WinHttp.WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
         IntPtr.Zero,
         0);
 }
开发者ID:JerryForNet,项目名称:corefx,代码行数:8,代码来源:WinHttpHandler.cs

示例7: SetRequestHandleClientCertificateOptions

        private void SetRequestHandleClientCertificateOptions(SafeWinHttpHandle requestHandle, Uri requestUri)
        {
            // Must be HTTPS scheme to use client certificates.
            if (requestUri.Scheme != UriSchemeHttps)
            {
                return;
            }

            // Get candidate list for client certificates.
            X509Certificate2Collection certs;
            if (_clientCertificateOption == ClientCertificateOption.Manual)
            {
                certs = ClientCertificates;
            }
            else
            {
                using (var myStore = new X509Store())
                {
                    myStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
                    certs = myStore.Certificates;
                }
            }

            // Check for no certs now as a performance optimization.
            if (certs.Count == 0)
            {
                SetNoClientCertificate(requestHandle);
                return;
            }

            // Reduce the set of certificates to match the proper 'Client Authentication' criteria.
            certs = certs.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.DigitalSignature, true);
            certs = certs.Find(X509FindType.FindByApplicationPolicy, ClientAuthenticationOID, true);

            // Build a new collection with certs that have a private key. Need to do this
            // manually because there is no X509FindType to match this criteria.
            var clientCerts = new X509Certificate2Collection();
            foreach (var cert in certs)
            {
                if (cert.HasPrivateKey)
                {
                    clientCerts.Add(cert);
                }
            }

            // TOOD: Filter the list based on TrustedIssuerList info from WINHTTP.

            // Set the client certificate.
            if (certs.Count == 0)
            {
                SetNoClientCertificate(requestHandle);
            }
            else
            {
                SetWinHttpOption(
                    requestHandle,
                    Interop.WinHttp.WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
                    clientCerts[0].Handle,
                    (uint)Marshal.SizeOf<Interop.Crypt32.CERT_CONTEXT>());
            }
        }
开发者ID:JerryForNet,项目名称:corefx,代码行数:61,代码来源:WinHttpHandler.cs

示例8: AddRequestHeaders

        private static void AddRequestHeaders(
            SafeWinHttpHandle requestHandle,
            HttpRequestMessage requestMessage,
            CookieContainer cookies)
        {
            var requestHeadersBuffer = new StringBuilder();

            // Manually add cookies.
            if (cookies != null)
            {
                string cookieHeader = GetCookieHeader(requestMessage.RequestUri, cookies);
                if (!string.IsNullOrEmpty(cookieHeader))
                {
                    requestHeadersBuffer.AppendLine(cookieHeader);
                }
            }

            // Serialize general request headers.
            requestHeadersBuffer.AppendLine(requestMessage.Headers.ToString());

            // Serialize entity-body (content) headers.
            if (requestMessage.Content != null)
            {
                // TODO: Content-Length header isn't getting correctly placed using ToString()
                // This is a bug in HttpContentHeaders that needs to be fixed.
                if (requestMessage.Content.Headers.ContentLength.HasValue)
                {
                    long contentLength = requestMessage.Content.Headers.ContentLength.Value;
                    requestMessage.Content.Headers.ContentLength = null;
                    requestMessage.Content.Headers.ContentLength = contentLength;
                }

                requestHeadersBuffer.AppendLine(requestMessage.Content.Headers.ToString());
            }

            // Add request headers to WinHTTP request handle.
            if (!Interop.WinHttp.WinHttpAddRequestHeaders(
                requestHandle,
                requestHeadersBuffer,
                (uint)requestHeadersBuffer.Length,
                Interop.WinHttp.WINHTTP_ADDREQ_FLAG_ADD))
            {
                WinHttpException.ThrowExceptionUsingLastError();
            }
        }
开发者ID:JerryForNet,项目名称:corefx,代码行数:45,代码来源:WinHttpHandler.cs

示例9: ParseResponseHeaders

        private void ParseResponseHeaders(
            SafeWinHttpHandle requestHandle,
            HttpResponseMessage response,
            bool stripEncodingHeaders)
        {
            string rawResponseHeaders = GetResponseHeaderStringInfo(
                requestHandle,
                Interop.WinHttp.WINHTTP_QUERY_RAW_HEADERS_CRLF);
            string[] responseHeaderArray = rawResponseHeaders.Split(
                s_httpHeadersSeparator,
                StringSplitOptions.RemoveEmptyEntries);

            // Parse the array of headers and split them between Content headers and Response headers.
            // Skip the first line which contains status code, etc. information that we already parsed.
            for (int i = 1; i < responseHeaderArray.Length; i++)
            {
                int colonIndex = responseHeaderArray[i].IndexOf(':');

                // Skip malformed header lines that are missing the colon character.
                if (colonIndex > 0)
                {
                    string headerName = responseHeaderArray[i].Substring(0, colonIndex);
                    string headerValue = responseHeaderArray[i].Substring(colonIndex + 1).Trim(); // Normalize header value by trimming white space.

                    if (!response.Headers.TryAddWithoutValidation(headerName, headerValue))
                    {
                        if (stripEncodingHeaders)
                        {
                            // Remove Content-Length and Content-Encoding headers if we are
                            // decompressing the response stream in the handler (due to 
                            // WINHTTP not supporting it in a particular downlevel platform). 
                            // This matches the behavior of WINHTTP when it does decompression iself.
                            if (string.Equals(
                                HeaderNameContentLength,
                                headerName,
                                StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            if (string.Equals(
                                HeaderNameContentEncoding,
                                headerName,
                                StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                        }

                        // TODO: Should we log if there is an error here?
                        response.Content.Headers.TryAddWithoutValidation(headerName, headerValue);
                    }
                }
            }
        }
开发者ID:JerryForNet,项目名称:corefx,代码行数:55,代码来源:WinHttpHandler.cs

示例10: GetResponseHeaderNumberInfo

        private uint GetResponseHeaderNumberInfo(SafeWinHttpHandle requestHandle, uint infoLevel)
        {
            uint result = 0;
            uint resultSize = sizeof(uint);

            if (!Interop.WinHttp.WinHttpQueryHeaders(
                requestHandle,
                infoLevel | Interop.WinHttp.WINHTTP_QUERY_FLAG_NUMBER,
                Interop.WinHttp.WINHTTP_HEADER_NAME_BY_INDEX,
                ref result,
                ref resultSize,
                IntPtr.Zero))
            {
                WinHttpException.ThrowExceptionUsingLastError();
            }

            return result;
        }
开发者ID:JerryForNet,项目名称:corefx,代码行数:18,代码来源:WinHttpHandler.cs

示例11: SetWinHttpOption

 private static void SetWinHttpOption(
     SafeWinHttpHandle handle,
     uint option,
     IntPtr optionData,
     uint optionSize)
 {
     if (!Interop.WinHttp.WinHttpSetOption(
         handle,
         option,
         optionData,
         optionSize))
     {
         WinHttpException.ThrowExceptionUsingLastError();
     }
 }
开发者ID:JerryForNet,项目名称:corefx,代码行数:15,代码来源:WinHttpHandler.cs

示例12: SetRequestHandleBufferingOptions

 private void SetRequestHandleBufferingOptions(SafeWinHttpHandle requestHandle)
 {
     uint optionData = (uint)_maxResponseHeadersLength;
     SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, ref optionData);
     optionData = (uint)_maxResponseDrainSize;
     SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, ref optionData);
 }
开发者ID:JerryForNet,项目名称:corefx,代码行数:7,代码来源:WinHttpHandler.cs

示例13: WinHttpAddRequestHeaders

 public static bool WinHttpAddRequestHeaders(
     SafeWinHttpHandle requestHandle,
     StringBuilder headers,
     uint headersLength,
     uint modifiers)
 {
     return true;
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:FakeInterop.cs

示例14: WinHttpSetStatusCallback

 public static IntPtr WinHttpSetStatusCallback(
     SafeWinHttpHandle handle,
     Interop.WinHttp.WINHTTP_STATUS_CALLBACK callback,
     uint notificationFlags,
     IntPtr reserved)
 {
     if (handle == null)
     {
         throw new ArgumentNullException("handle");
     }
     
     return IntPtr.Zero;
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:13,代码来源:FakeInterop.cs

示例15: WinHttpGetProxyForUrl

        public static bool WinHttpGetProxyForUrl(
            SafeWinHttpHandle sessionHandle,
            string url,
            ref Interop.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
            out Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo)
        {
            if (TestControl.PACFileNotDetectedOnNetwork)
            {
                proxyInfo.AccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
                proxyInfo.Proxy = IntPtr.Zero;
                proxyInfo.ProxyBypass = IntPtr.Zero;

                TestControl.LastWin32Error = (int)Interop.WinHttp.ERROR_WINHTTP_AUTODETECTION_FAILED;
                return false;
            }

            proxyInfo.AccessType = Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY;
            proxyInfo.Proxy = Marshal.StringToHGlobalUni(FakeRegistry.WinInetProxySettings.Proxy);
            proxyInfo.ProxyBypass = IntPtr.Zero;

            return true;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:22,代码来源:FakeInterop.cs


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