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


C# HttpContentHeaders.Add方法代码示例

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


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

示例1: ContentLength_AddInvalidValueUsingUnusualCasing_ParserRetrievedUsingCaseInsensitiveComparison

        public void ContentLength_AddInvalidValueUsingUnusualCasing_ParserRetrievedUsingCaseInsensitiveComparison()
        {
            _headers = new HttpContentHeaders(new ComputeLengthHttpContent(() => 15));

            // Use uppercase header name to make sure the parser gets retrieved using case-insensitive comparison.
            Assert.Throws<FormatException>(() => { _headers.Add("CoNtEnT-LeNgTh", "this is invalid"); });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:HttpContentHeadersTest.cs

示例2: CopyHeaders

 private static void CopyHeaders(HttpContentHeaders fromHeaders,
                                 HttpContentHeaders toHeaders)
 {
     foreach (KeyValuePair<string, IEnumerable<string>> header in fromHeaders) {
         toHeaders.Add(header.Key, header.Value);
     }
 }
开发者ID:cairabbit,项目名称:daf,代码行数:7,代码来源:HeadMessageHandler.cs

示例3: PopulateHeaders

        public static void PopulateHeaders(this HttpPacket packet, HttpContentHeaders contentHeaders, HttpHeaders generalHeaders)
        {
            if (packet == null) throw new ArgumentNullException("packet");

            string hdrKey;
            foreach (var hdr in packet.Headers)
            {
                if (hdr.Key == null) continue;

                hdrKey = hdr.Key.Trim().ToUpperInvariant();

                if (hdrKey == "CONTENT-LENGTH") continue; //Content Length is automaitically calculated

                if (Array.IndexOf<String>(contentOnlyHeaders, hdrKey) >= 0)
                {
                    //TODO: Confirm if HttpResponseMessage/HttpRequestMessage will break headers into "," commas whereas in actuality header in Packet is an entire header
                    contentHeaders.Add(hdr.Key.Trim(), hdr.Value);
                }
                else
                {
                    generalHeaders.Add(hdr.Key.Trim(), hdr.Value);
                }

                //TODO: Check if a string can be parsed properly into the typed header

                //Test adding multiple headers of the same name will do. // Look up the Add overload that takes an ienumerable<string> to figure out its purpose.
            }
        }
开发者ID:BrisWhite,项目名称:RestBus,代码行数:28,代码来源:HttpHelpers.cs

示例4: PopulateHeaders

        /// <summary>
        /// Populates contentheaders and generalheaders with headers from the <see cref="HttpPacket"/>>
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="contentHeaders"></param>
        /// <param name="generalHeaders"></param>
        public static void PopulateHeaders(this HttpPacket packet, HttpContentHeaders contentHeaders, HttpHeaders generalHeaders)
        {
            if (packet == null) throw new ArgumentNullException("packet");

            bool dateHeaderProcessed = false;
            string hdrKey;
            foreach (var hdr in packet.Headers)
            {
                if (hdr.Key == null) continue;

                hdrKey = hdr.Key.Trim().ToUpperInvariant();

                if (hdrKey == "CONTENT-LENGTH")
                {
                    continue; //Content Length is automatically calculated by System.Net.Http.ByteArrayContent
                }
                else if (hdrKey == "DATE")
                {
                    if (dateHeaderProcessed) continue; //Already Processed
                    dateHeaderProcessed = true;

                    //Date Header in wrong format causes exception in System.Net.Http.HttpResponseMessage/HttpRequestMessage
                    //TODO: Confirm that this exception still occurs in the newer Nuget version of System.Net.Http

                    //Check if the date string is in RFC 1123 format
                    var val = (hdr.Value == null || !hdr.Value.Any()) ? null : hdr.Value.First().Trim();
                    if(val != null && Common.Shared.IsValidHttpDate(val))
                    {
                        generalHeaders.Add("Date", val);
                    }

                    continue;
                }

                if (Array.IndexOf<String>(contentOnlyHeaders, hdrKey) >= 0)
                {
                    contentHeaders.Add(hdr.Key.Trim(), hdr.Value);
                }
                else
                {
                    generalHeaders.Add(hdr.Key.Trim(), hdr.Value);
                }
            }
        }
开发者ID:bestwpw,项目名称:RestBus,代码行数:50,代码来源:HttpHelpers.cs

示例5: CopyTo

        /// <summary>Copies all headers from the source to the target.</summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="handleContentLength">true to handle content length.</param>
        /// <param name="handleContentEncoding">true to handle content encoding.</param>
        /// <param name="handleChangedValues">true to handle changed values.</param>
        public static void CopyTo(
            this HttpContentHeaders source,
            HttpContentHeaders target,
            bool handleContentLength = true,
            bool handleContentEncoding = true,
            bool handleChangedValues = false)
        {
            // Remove headers we are going to rewrite and headers with null values
            foreach (var header in source)
            {
                try
                {
                    if (!handleContentLength && header.Key.Equals("Content-Length", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (!handleContentEncoding && header.Key.Equals("Content-Encoding", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    if (!handleChangedValues)
                    {
                        // If values have changed, dont update it
                        if (target.Contains(header.Key))
                        {
                            if (target.GetValues(header.Key).Any(targetValue => header.Value.Any(originalValue => originalValue != targetValue)))
                            {
                                return;
                            }
                        }
                    }

                    target.Add(header.Key, header.Value);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }
开发者ID:SneakyMax,项目名称:Microsoft.AspNet.WebApi.MessageHandlers.Compression,代码行数:48,代码来源:HttpContentHeaderExtensions.cs

示例6: SetDefaultContentHeaders

 public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
 {
     base.SetDefaultContentHeaders(type, headers, mediaType);
     string name = HttpContext.Current.Request.Url.Segments[HttpContext.Current.Request.Url.Segments.Length-1];
     headers.Add("Content-Disposition", "attachment; filename=" + name + ".csv");
 }
开发者ID:kennisnet,项目名称:Sparql-Query-Api,代码行数:6,代码来源:RdfCsvMediaTypeFormatter.cs

示例7: SetDefaultContentHeaders

 public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
 {
     base.SetDefaultContentHeaders(type, headers, mediaType);
     headers.Add("Content-Disposition", "attachment; filename=" + Filename);
 }
开发者ID:theorigin,项目名称:WebApi-CSVFormatter,代码行数:5,代码来源:CsvFormatter.cs

示例8: SetDefaultContentHeaders

        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            base.SetDefaultContentHeaders(type, headers, mediaType);

            headers.Add("Content-Disposition", string.Format("attachment; filename={0}", CsvFileName));
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:6,代码来源:ProjectForAdminCsvFormatter.cs

示例9: SetDefaultContentHeaders

 /// <summary>Sets the default content headers.</summary>
 /// <param name="type">The <see cref="Type"/>.</param>
 /// <param name="headers">The <see cref="HttpContentHeaders"/>.</param>
 /// <param name="mediaType">The <see cref="MediaTypeHeaderValue"/>.</param>
 public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
 {
     headers.Add("Content-Disposition", "attachment; filename=\"" + type.Name + ".csv\"");
     base.SetDefaultContentHeaders(type, headers, mediaType);
 }
开发者ID:stevenbey,项目名称:beyond.utilities,代码行数:9,代码来源:CsvMediaTypeFormatter.cs

示例10: SetDefaultContentHeaders

        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            headers.Add(RestfulServiceConstants.RqModelTypeHeaderKey, EncryptionManager.Encrypt(type.AssemblyQualifiedName));

            base.SetDefaultContentHeaders(type, headers, mediaType);
        }
开发者ID:chenzuo,项目名称:ProtoBuf.Services,代码行数:6,代码来源:ProtoBufMediaTypeFormatter.cs


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