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


C# HttpListenerRequest.GetClientCertificate方法代码示例

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


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

示例1: ConvertRequest

        private Request ConvertRequest(Uri baseUri, HttpListenerRequest httpRequest)
        {
            var expectedRequestLength = GetExpectedRequestLength(ConvertToDictionary(httpRequest.Headers));

            var url = new Url
            {
                Scheme = httpRequest.Url.Scheme,
                HostName = httpRequest.Url.Host,
                Port = httpRequest.Url.IsDefaultPort ? null : (int?)httpRequest.Url.Port,
                BasePath = baseUri.AbsolutePath.TrimEnd('/'),
                Path = baseUri.MakeAppLocalPath(httpRequest.Url),
                Query = httpRequest.Url.Query,
            };

            var fieldCount = httpRequest.ProtocolVersion.Major == 2 ? 1 : 2;
            var protocolVersion = string.Format("HTTP/{0}", httpRequest.ProtocolVersion.ToString(fieldCount));

            byte[] certificate = null;
            if (httpRequest.IsSecureConnection)
            {
                var x509Certificate = httpRequest.GetClientCertificate();
                if (x509Certificate != null)
                {
                    certificate = x509Certificate.RawData;
                }
            }

            return new Request(
                httpRequest.HttpMethod,
                url,
                RequestStream.FromStream(httpRequest.InputStream, expectedRequestLength, false),
                ConvertToDictionary(httpRequest.Headers),
                (httpRequest.RemoteEndPoint != null) ? httpRequest.RemoteEndPoint.Address.ToString() : null,
                protocolVersion,
                certificate);
        }
开发者ID:gaochundong,项目名称:Happer,代码行数:36,代码来源:Engine.cs

示例2: ConvertRequestToNancyRequest

        private Request ConvertRequestToNancyRequest(HttpListenerRequest request)
        {
            var baseUri = this.baseUriList.FirstOrDefault(uri => uri.IsCaseInsensitiveBaseOf(request.Url));

            if (baseUri == null)
            {
                throw new InvalidOperationException(String.Format("Unable to locate base URI for request: {0}",request.Url));
            }

            var expectedRequestLength =
                GetExpectedRequestLength(request.Headers.ToDictionary());

            var relativeUrl = baseUri.MakeAppLocalPath(request.Url);

            var nancyUrl = new Url
            {
                Scheme = request.Url.Scheme,
                HostName = request.Url.Host,
                Port = request.Url.IsDefaultPort ? null : (int?)request.Url.Port,
                BasePath = baseUri.AbsolutePath.TrimEnd('/'),
                Path = HttpUtility.UrlDecode(relativeUrl),
                Query = request.Url.Query,
                Fragment = request.Url.Fragment,
            };

            byte[] certificate = null;

            if (this.configuration.EnableClientCertificates)
            {
                var x509Certificate = request.GetClientCertificate();

                if (x509Certificate != null)
                {
                    certificate = x509Certificate.RawData;
                }
            }

            return new Request(
                request.HttpMethod,
                nancyUrl,
                RequestStream.FromStream(request.InputStream, expectedRequestLength, false),
                request.Headers.ToDictionary(),
                (request.RemoteEndPoint != null) ? request.RemoteEndPoint.Address.ToString() : null,
                certificate);
        }
开发者ID:jmcota,项目名称:Nancy,代码行数:45,代码来源:NancyHost.cs

示例3: ConstructRequestInfo

        /// <summary>
        /// Create an <see cref="HttpMessage.Request"/> object out of the given
        /// <paramref name="originalRequest"/>.
        /// </summary>
        /// <param name="originalRequest">The original request to mimic.</param>
        /// <returns>An <see cref="HttpMessage.Request"/> object containing the request.</returns>
        private static HttpMessage.Request ConstructRequestInfo(
            HttpListenerRequest originalRequest)
        {
            HttpMessage.Request requestInfo = new HttpMessage.Request();

            // Copy the request Uri and Method
            requestInfo.RequestUri = originalRequest.Url;
            requestInfo.Method = originalRequest.HttpMethod;

            // Copy all relevant headers to the request
            requestInfo.Headers = new HttpMessage.HeaderCollection();
            foreach (string headerKey in originalRequest.Headers.AllKeys)
            {
                if (headerKey.Equals("User-Agent", StringComparison.OrdinalIgnoreCase))
                {
                    requestInfo.UserAgent = originalRequest.Headers[headerKey];
                }
                else if (headerKey.Equals("Content-Type", StringComparison.OrdinalIgnoreCase))
                {
                    requestInfo.ContentType = originalRequest.Headers[headerKey];
                }
                else if (headerKey.Equals("Accept", StringComparison.OrdinalIgnoreCase))
                {
                    requestInfo.Accept = originalRequest.Headers[headerKey];
                }
                else if (!headerKey.Equals("Connection", StringComparison.OrdinalIgnoreCase) &&
                         !headerKey.Equals("Host", StringComparison.OrdinalIgnoreCase) &&
                         !headerKey.Equals("Content-Length", StringComparison.OrdinalIgnoreCase) &&
                         !headerKey.Equals("Expect", StringComparison.OrdinalIgnoreCase))
                {
                    requestInfo.Headers.Add(new HttpMessage.Header
                    {
                        Name = headerKey,
                        Value = originalRequest.Headers[headerKey]
                    });
                }
            }

            // Copy response cookies
            requestInfo.Cookies = new HttpMessage.CookieCollection();
            foreach (Cookie cookie in originalRequest.Cookies)
            {
                requestInfo.Cookies.Add(new HttpMessage.Cookie
                {
                    Name = cookie.Name,
                    Value = cookie.Value,
                });
            }

            // Copy response stream
            if (originalRequest.Headers.AllKeys.Contains("Content-Length"))
            {
                using (StreamReader reader = new StreamReader(originalRequest.InputStream))
                {
                    requestInfo.RequestText = reader.ReadToEnd();
                }
            }

            // Retrieve the certificate on the request if any.
            requestInfo.Certificate = originalRequest.GetClientCertificate();

            return requestInfo;
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:69,代码来源:MockHttpServer.cs

示例4: ConvertRequestToNancyRequest

        private Request ConvertRequestToNancyRequest(HttpListenerRequest request)
        {
            var baseUri = this.GetBaseUri(request);

            if (baseUri == null)
            {
                throw new InvalidOperationException(string.Format("Unable to locate base URI for request: {0}",request.Url));
            }

            var expectedRequestLength =
                GetExpectedRequestLength(request.Headers.ToDictionary());

            var relativeUrl = baseUri.MakeAppLocalPath(request.Url);

            var nancyUrl = new Url
            {
                Scheme = request.Url.Scheme,
                HostName = request.Url.Host,
                Port = request.Url.IsDefaultPort ? null : (int?)request.Url.Port,
                BasePath = baseUri.AbsolutePath.TrimEnd('/'),
                Path = HttpUtility.UrlDecode(relativeUrl),
                Query = request.Url.Query,
            };

            byte[] certificate = null;

            if (this.configuration.EnableClientCertificates)
            {
                var x509Certificate = request.GetClientCertificate();

                if (x509Certificate != null)
                {
                    certificate = x509Certificate.RawData;
                }
            }

            // NOTE: For HTTP/2 we want fieldCount = 1,
            // otherwise (HTTP/1.0 and HTTP/1.1) we want fieldCount = 2
            var fieldCount = request.ProtocolVersion.Major == 2 ? 1 : 2;

            var protocolVersion = string.Format("HTTP/{0}", request.ProtocolVersion.ToString(fieldCount));

            return new Request(
                request.HttpMethod,
                nancyUrl,
                RequestStream.FromStream(request.InputStream, expectedRequestLength, StaticConfiguration.DisableRequestStreamSwitching ?? false),
                request.Headers.ToDictionary(),
                (request.RemoteEndPoint != null) ? request.RemoteEndPoint.Address.ToString() : null,
                certificate,
                protocolVersion);
        }
开发者ID:afwilliams,项目名称:Nancy,代码行数:51,代码来源:NancyHost.cs


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