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


C# HttpHeaders.TryAddWithoutValidation方法代码示例

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


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

示例1: CreateHeaderFields

        /// <summary>
        /// Copies the unsorted header fields to a sorted collection.
        /// </summary>
        /// <param name="source">The unsorted source headers</param>
        /// <param name="destination">The destination <see cref="HttpRequestHeaders"/> or <see cref="HttpResponseHeaders"/>.</param>
        /// <param name="contentStream">The input <see cref="Stream"/> used to form any <see cref="HttpContent"/> being part of this HTTP request.</param>
        /// <param name="rewind">Start location of any request entity within the <paramref name="contentStream"/>.</param>
        /// <returns>An <see cref="HttpContent"/> instance if header fields contained and <see cref="HttpContentHeaders"/>.</returns>
        private static HttpContent CreateHeaderFields(HttpHeaders source, HttpHeaders destination, Stream contentStream, int rewind)
        {
            Contract.Assert(source != null, "source headers cannot be null");
            Contract.Assert(destination != null, "destination headers cannot be null");
            Contract.Assert(contentStream != null, "contentStream must be non null");
            HttpContentHeaders contentHeaders = null;
            HttpContent content = null;

            // Set the header fields
            foreach (KeyValuePair<string, IEnumerable<string>> header in source)
            {
                if (!destination.TryAddWithoutValidation(header.Key, header.Value))
                {
                    if (contentHeaders == null)
                    {
                        contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();
                    }

                    contentHeaders.TryAddWithoutValidation(header.Key, header.Value);
                }
            }

            // If we have content headers then create an HttpContent for this Response
            if (contentHeaders != null)
            {
                // Need to rewind the input stream to be at the position right after the HTTP header
                // which we may already have parsed as we read the content stream.
                if (!contentStream.CanSeek)
                {
                    throw Error.InvalidOperation(Resources.HttpMessageContentStreamMustBeSeekable, "ContentReadStream", FormattingUtilities.HttpResponseMessageType.Name);
                }

                contentStream.Seek(0 - rewind, SeekOrigin.Current);
                content = new StreamContent(contentStream);
                contentHeaders.CopyTo(content.Headers);
            }

            return content;
        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:47,代码来源:HttpContentMessageExtensions.cs

示例2: MergeWebHeaderCollectionWithHttpHeaders

 internal static void MergeWebHeaderCollectionWithHttpHeaders(WebHeaderCollection headersToMerge, HttpHeaders mainHeaders, HttpHeaders contentHeaders)
 {
     foreach (string headerKey in headersToMerge.AllKeys)
     {
         if (WellKnownContentHeaders.Contains(headerKey))
         {
             contentHeaders.TryAddWithoutValidation(headerKey, headersToMerge[headerKey]);
         }
         else
         {
             mainHeaders.TryAddWithoutValidation(headerKey, headersToMerge[headerKey]);
         }
     }
 }
开发者ID:weshaggard,项目名称:wcf,代码行数:14,代码来源:HttpRequestMessageExtensionMethods.cs

示例3: CopyTo

            /// <summary>
            /// Copies current header field to the provided <see cref="HttpHeaders"/> instance.
            /// </summary>
            /// <param name="headers">The headers.</param>
            /// <param name="ignoreHeaderValidation">Set to false to validate headers</param>
            public void CopyTo(HttpHeaders headers, bool ignoreHeaderValidation)
            {
                var name = _name.ToString();
                var value = _value.ToString().Trim(CurrentHeaderFieldStore._linearWhiteSpace);

                if (ignoreHeaderValidation)
                {
                    headers.TryAddWithoutValidation(name, value);
                }
                else
                {
                    headers.Add(name, value);
                }

                Clear();
            }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:21,代码来源:InternetMessageFormatHeaderParser.cs

示例4: TryAddHeader

        public bool TryAddHeader(HttpHeaders headers, string value)
        {
            Fx.Assert(headers != null, "The 'headers' parameter should never be null.");
            if (!headers.TryAddWithoutValidation(this.Name, value))
            {
                this.UpdateHeaderInfo(headers);
                return false;
            }

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


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