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


C# HttpHeaders.TryGetValues方法代码示例

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


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

示例1: GetHeaderString

        private static string GetHeaderString(HttpHeaders headers, string name)
        {
            IEnumerable<string> values;

            if (headers.TryGetValues(name, out values))
            {
                return values.FirstOrDefault();
            }

            return null;
        }
开发者ID:MetSystem,项目名称:dotnet-apiport,代码行数:11,代码来源:ServiceHeaders.cs

示例2: CheckAuthToken

		/// <summary>
		/// Checks for authorization header and then validates the token in the header
		/// </summary>
		/// <param name="theHeaders"></param>
		/// <returns></returns>
		private bool CheckAuthToken(HttpHeaders theHeaders)
		{
			var aValues = Enumerable.Empty<string>();

			theHeaders.TryGetValues("Authorization", out aValues);

			if (aValues == null)
				return false;

			var aValueList = aValues as IList<string> ?? aValues.ToList();
			if (!aValueList.Any())
				return false;

			var aValue = aValueList.FirstOrDefault();
			if (string.IsNullOrEmpty(aValue))
				return false;

			return _loginService.ValidateToken(aValue);
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:24,代码来源:POCAuthorizationAttribute.cs

示例3: GetODataVersion

        private static ODataVersion? GetODataVersion(HttpHeaders headers, params string[] headerNames)
        {
            foreach (string headerName in headerNames)
            {
                IEnumerable<string> values;
                if (headers.TryGetValues(headerName, out values))
                {
                    string value = values.FirstOrDefault();
                    if (value != null)
                    {
                        string trimmedValue = value.Trim(' ', ';');
                        try
                        {
                            return ODataUtils.StringToODataVersion(trimmedValue);
                        }
                        catch (ODataException)
                        {
                            // Parsing ODataVersion failed, try next header
                        }
                    }
                }
            }

            return null;
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:25,代码来源:ODataMediaTypeFormatter.cs

示例4: ComputeCanonicalizedHeaders

        private static string ComputeCanonicalizedHeaders(string httpMethod, HttpHeaders httpHeaders)
        {
            var headers = httpHeaders
                .Where(x => x.Key.StartsWith("x-ms-"))
                .OrderBy(x => x.Key);

            var httpMethodToUpper = httpMethod.ToUpper();

            var contentLength = httpMethodToUpper == "GET" ? string.Empty : "0";
            IEnumerable<string> values;
            if (httpHeaders.TryGetValues("Content-Length", out values))
                contentLength = values.First();

            var stringToHash = string.Format("{0}\n\n\n{1}\n\n\n\n\n\n\n\n\n", httpMethodToUpper, contentLength);

            return headers.Aggregate(stringToHash, (current, header) => current + string.Format("{0}:{1}\n", header.Key.ToLower(), header.Value.First()));
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:17,代码来源:RavenAzureClient.cs

示例5: TryGetHeader

 private string TryGetHeader(HttpHeaders headers, string headerName)
 {
     IEnumerable<string> values;
     if (headers.TryGetValues(headerName, out values))
     {
         return values.FirstOrDefault();
     }
     return String.Empty;
 }
开发者ID:farukc,项目名称:Dash,代码行数:9,代码来源:ContainerController.cs

示例6: GetFirstHeaderValue

        private string GetFirstHeaderValue(HttpHeaders headers, string key)
        {
            IEnumerable<string> headerValues = null;
            if (headers.TryGetValues(key, out headerValues))
                return headerValues.FirstOrDefault();

            return string.Empty;
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:8,代码来源:HttpClientResponseData.cs

示例7: Contains

        /// <summary>
        /// Asserts the given <see cref="HttpHeaders"/> contain the given <paramref name="values"/>
        /// for the given <paramref name="name"/>.
        /// </summary>
        /// <param name="headers">The <see cref="HttpHeaders"/> to examine.  It cannot be <c>null</c>.</param>
        /// <param name="name">The name of the header.  It cannot be empty.</param>
        /// <param name="values">The values that must all be present.  It cannot be null.</param>
        public void Contains(HttpHeaders headers, string name, params string[] values)
        {
            Assert.NotNull(headers);
            Assert.False(String.IsNullOrWhiteSpace(name), "Test error: name cannot be empty.");
            Assert.NotNull(values);

            IEnumerable<string> headerValues = null;
            bool foundIt = headers.TryGetValues(name, out headerValues);
            Assert.True(foundIt);

            foreach (string value in values)
            {
                Assert.Contains(value, headerValues);
            }
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:22,代码来源:HttpAssert.cs

示例8: ConvertToNameValueCollection

        /// <summary>
        /// Converts the specified headers to name value collection, where the value is the first header value encountered.
        /// </summary>
        /// <param name="headers">The headers to convert.</param>
        /// <returns>A NameValueCollection of headers and a comma separated concatenation of their values.</returns>

        private static NameValueCollection ConvertToNameValueCollection(HttpHeaders headers)
        {
            var collection = new NameValueCollection();
            if (headers != null)
            {
                foreach (var header in headers)
                {
                    var concatenatedValue = string.Empty;
                    IEnumerable<string> values;
                    if (headers.TryGetValues(header.Key, out values))
                    {
                        concatenatedValue = values.Aggregate(concatenatedValue, (current, value) => current + value + ",");
                    }

                    concatenatedValue = concatenatedValue.TrimEnd(',');

                    collection.Add(header.Key, concatenatedValue);
                }
            }
            
            return collection;
        }
开发者ID:blowdart,项目名称:Idunno.WebApi.SharedKeyAuth,代码行数:28,代码来源:SharedKeySignature.cs

示例9: Contains

        /// <summary>
        /// Asserts the given <see cref="HttpHeaders"/> contain the given <paramref name="values"/>
        /// for the given <paramref name="name"/>.
        /// </summary>
        /// <param name="headers">The <see cref="HttpHeaders"/> to examine.  It cannot be <c>null</c>.</param>
        /// <param name="name">The name of the header.  It cannot be empty.</param>
        /// <param name="values">The values that must all be present.  It cannot be null.</param>
        public static void Contains(HttpHeaders headers, string name, params string[] values)
        {
            Assert.IsNotNull(headers, "Test error: headers cannot be null.");
            Assert.IsFalse(string.IsNullOrWhiteSpace(name), "Test error: name cannot be empty.");
            Assert.IsNotNull(values, "Test error: values cannot be null.");

            IEnumerable<string> headerValues = null;
            bool foundIt = headers.TryGetValues(name, out headerValues);
            Assert.IsTrue(foundIt, "Headers did not contain a header named " + name);
            CollectionAssert.IsSubsetOf(values.ToList(), headerValues.ToList(), "Headers did not contain any or all of the expected headers.");
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:18,代码来源:HttpAssert.cs

示例10: GetHeaderValue

        /// <summary>
        /// Retrieve the string value associated with the header of the passed name.
        /// </summary>
        /// <param name="headers">Request headers to check.</param>
        /// <param name="headerName">Name of the header.</param>
        /// <exception cref="ArgumentNullException">Parameter headers is null.</exception>
        /// <exception cref="InvalidOperationException">Duplicate headers were found.</exception>
        /// <returns>String value associated with the header if found; null otherwise.</returns>
        internal static string GetHeaderValue(HttpHeaders headers, string headerName)
        {
            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            string value = null;
            IEnumerable<String> headerValues;

            if (headers.TryGetValues(headerName, out headerValues))
            {
                value = headerValues.SingleOrDefault();
            }

            return value;
        }
开发者ID:ZiNETHQ,项目名称:sif3-framework-dotnet,代码行数:25,代码来源:HttpUtils.cs

示例11: TryGetHeader

        public IEnumerable<string> TryGetHeader(HttpHeaders headers)
        {
            Fx.Assert(headers != null, "The 'headers' parameter should never be null.");
            
            IEnumerable<string> values = null;

            if (!headers.TryGetValues(this.Name, out values))
            {
                values = null;
                this.UpdateHeaderInfo(headers);
            }

            return values;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:14,代码来源:HttpHeaderInfo.cs

示例12: GetODataVersion

        private static ODataVersion? GetODataVersion(HttpHeaders headers, string headerName)
        {
            ODataVersion? version = null;
            IEnumerable<string> values;

            if (headers.TryGetValues(headerName, out values))
            {
                foreach (string value in values)
                {
                    string trimmedValue = value.Trim(' ', ';');
                    version = GetODataVersion(trimmedValue);
                }
            }

            return version;
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:16,代码来源:ODataMediaTypeFormatter.cs


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