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


C# HttpHeaders.Add方法代码示例

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


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

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

示例2: Adding_nonstandard_header_name_is_ok

        public void Adding_nonstandard_header_name_is_ok()
        {
            var headers = new HttpHeaders();

            headers.Add("FOOBAR", "123");

            headers.GetFirst<string>("FOOBAR").ShouldBe("123");
        }
开发者ID:jwynia,项目名称:stormpath-sdk-dotnet,代码行数:8,代码来源:HttpHeaders_tests.cs

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

示例4: CopyTo

 /// <summary>
 /// Copies current header field to the provided <see cref="HttpHeaders"/> instance.
 /// </summary>
 /// <param name="headers">The headers.</param>
 public void CopyTo(HttpHeaders headers)
 {
     headers.Add(_name.ToString(), _value.ToString().Trim(CurrentHeaderFieldStore._linearWhiteSpace));
     Clear();
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:9,代码来源:InternetMessageFormatHeaderParser.cs

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

示例6: AddMessageHeaders

 private static void AddMessageHeaders(HttpHeaders headers)
 {
     headers.Add("N1", new string[] { "V1a", "V1b", "V1c", "V1d", "V1e" });
     headers.Add("N2", "V2");
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:5,代码来源:HttpMessageContentTests.cs

示例7: AddAuthCookie

 private void AddAuthCookie(HttpHeaders requestHeaders, string cookieValue)
 {
     requestHeaders.Add("Cookie", String.Format("{0}={1}", IdentityCookieName, cookieValue));
 }
开发者ID:leloulight,项目名称:Templates,代码行数:4,代码来源:StarterWebAIIndividualAuthTests.cs

示例8: AddCookiesToRequest

 private void AddCookiesToRequest(HttpHeaders responseHeaders, HttpHeaders requestHeaders)
 {
     var cookiehHeaders = responseHeaders.GetValues("Set-Cookie");
     foreach (var header in cookiehHeaders)
     {
         var cookieParts = header.Split(';');
         var cookie = cookieParts[0];
         var parts = cookie.Split('=');
         requestHeaders.Add("Cookie", String.Format("{0}={1}", parts[0], parts[1]));
     }
 }
开发者ID:leloulight,项目名称:Templates,代码行数:11,代码来源:StarterWebAIIndividualAuthTests.cs

示例9: HttpHeadersAddTest

		public void HttpHeadersAddTest()
		{
			var HttpHeaders = new HttpHeaders();
			Assert.AreEqual("[]", HttpHeaders.AsEnumerable<HttpHeader>().ToJsonString());
			HttpHeaders.Add("Content-Type", "text/html");
			HttpHeaders.Set("Content-Type", "text/plain");
			HttpHeaders.Set("cOntEnt-type", "text/plain");
			Assert.AreEqual(1, HttpHeaders.Count());
			Assert.AreEqual("cOntEnt-type: text/plain", String.Join("|", HttpHeaders.AsEnumerable()));
		}
开发者ID:soywiz,项目名称:NodeNetAsync,代码行数:10,代码来源:HttpHeadersTest.cs


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