• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# HttpHeaders类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestHeadersInOrder

        public static void TestHeadersInOrder()
        {
            string[] c1 = { "E2E4" };
            string h_c1 = "Connection: E2E4\r\n";
            string[] c2 = { "E7E5" };
            string h_c2 = "Connection: E7E5\r\n";
            string host = "chez.moi";
            string h_host = "Host: " + host + "\r\n";
            int ContentLength = 1951;
            string h_cl = "Content-Length: 1951\r\n";

            var hh = new HttpHeaders();
            hh.Connection = c1;
            Assert.AreEqual(h_c1, hh.HeadersInOrder);
            hh.Host = host;
            Assert.AreEqual(h_c1 + h_host, hh.HeadersInOrder);
            hh.Connection = c2;
            Assert.AreEqual(h_c2 + h_host, hh.HeadersInOrder);
            hh.Connection = null;
            Assert.AreEqual(h_host, hh.HeadersInOrder);
            hh.ContentLength = (uint?) ContentLength;
            Assert.AreEqual(h_host + h_cl, hh.HeadersInOrder);
            hh.ContentLength = null;
            Assert.AreEqual(h_host, hh.HeadersInOrder);
            hh.Host = null;
            Assert.IsTrue(String.IsNullOrEmpty(hh.HeadersInOrder));
        }
开发者ID:greenoaktree,项目名称:TrotiNet,代码行数:27,代码来源:TestHeaders.cs


示例2: ConvertToHeaders

        protected Dictionary<string, string> ConvertToHeaders(string name, HttpHeaders headers)
        {
            var result = headers.ToDictionary(x => x.Key, x => x.Value.FirstOrDefault());
            result.Add("Host", GetHost(name));

            return result;
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:7,代码来源:RavenAwsClient.cs


示例3: ServerSniffer

        public async Task<IActionResult> ServerSniffer(string uri)
        {

            var request_headers = new Dictionary<string, string>();
            var response_headers = new Dictionary<string, string>();

            var http_headers = new HttpHeaders();
            http_headers.RequestHeaders = request_headers;
            http_headers.ResponseHeaders = response_headers;
            using (var http_client = new HttpClient())
            {
                var request = new HttpRequestMessage(HttpMethod.Head, uri);
                using (var response = await http_client.SendAsync(request))
                {
                    foreach (var header in response.Headers)
                    {
                        response_headers.Add(header.Key, string.Join(",", header.Value));
                    }
                    foreach (var header in request.Headers)
                    {
                        request_headers.Add(header.Key, string.Join(",", header.Value));
                    }
                }
            }
            var json_result = new JsonResult(http_headers);
            return json_result;
        }
开发者ID:speedsticko,项目名称:WebDevTools,代码行数:27,代码来源:ToolsController.cs


示例4: TestMultilineParse

        public void TestMultilineParse()
        {
            //
            // multiline values are acceptable if the next
            // line starts with spaces
            //
            string header = @"HeaderName: Some multiline
              								value";

            HttpHeaders headers = new HttpHeaders ();

            headers.Parse (new StringReader (header));

            Assert.AreEqual ("Some multiline value", headers ["HeaderName"], "a1");

            header = @"HeaderName: Some multiline
              								value
            that spans
            a bunch of lines";

            headers = new HttpHeaders ();
            headers.Parse (new StringReader (header));

            Assert.AreEqual ("Some multiline value that spans a bunch of lines", headers ["HeaderName"], "a2");
        }
开发者ID:KevinT,项目名称:manos,代码行数:25,代码来源:HttpHeadersTest.cs


示例5: AuthorizeUser

        private static async Task<bool> AuthorizeUser(HttpHeaders headers)
        {
            HttpContext.Current.User = await GetClaimsForRoleAsync(headers)
                .ConfigureAwait(continueOnCapturedContext: false);

            return HttpContext.Current.User.Identity.IsAuthenticated;
        }
开发者ID:alexandercessac,项目名称:Lib,代码行数:7,代码来源:LyricsController.cs


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


示例7: GetClaimsForRoleAsync

 private static async Task<ClaimsPrincipal> GetClaimsForRoleAsync(HttpHeaders role)
 {
     return await Task.Run(() => new ClaimsPrincipal(new List<ClaimsIdentity>
     {
         new ClaimsIdentity("SecureAuth", "SafeType", role.GetValues("RoleType").FirstOrDefault())
     }));
 }
开发者ID:alexandercessac,项目名称:Lib,代码行数:7,代码来源:LyricsController.cs


示例8: DummyProxy

 public DummyProxy(string fakeEncoding)
     : base(new HttpSocket(new Socket(AddressFamily.InterNetwork,
         SocketType.Dgram, ProtocolType.Udp)))
 {
     ResponseHeaders = new HttpHeaders();
     ResponseHeaders.ContentEncoding = fakeEncoding;
 }
开发者ID:Gizeta,项目名称:Nekoxy-fiddler,代码行数:7,代码来源:TestDecompress.cs


示例9: RequestHeaderMap

 public RequestHeaderMap(HttpHeaders headers)
 {
     this.headersCollection = headers.ToDictionary(
           x => x.Key.ToLower().Replace("-", string.Empty),
           x => string.Join(",", x.Value)
     );
 }
开发者ID:WaffleSquirrel,项目名称:ZM.SignalR,代码行数:7,代码来源:RequestHeaderMap.cs


示例10: DefaultHttpRequest

 // Copy constructor
 public DefaultHttpRequest(IHttpRequest existingRequest, Uri overrideUri = null)
 {
     this.body = existingRequest.Body;
     this.bodyContentType = existingRequest.BodyContentType;
     this.headers = new HttpHeaders(existingRequest.Headers);
     this.method = existingRequest.Method.Clone();
     this.canonicalUri = new CanonicalUri(existingRequest.CanonicalUri, overrideResourcePath: overrideUri);
 }
开发者ID:jwynia,项目名称:stormpath-sdk-dotnet,代码行数:9,代码来源:DefaultHttpRequest.cs


示例11: GetHttpRequestHeader

        private static string GetHttpRequestHeader(HttpHeaders headers, string headerName)
        {
            if (!headers.Contains(headerName))
                return string.Empty;

            return headers.GetValues(headerName)
                            .SingleOrDefault();
        }
开发者ID:nexaddo,项目名称:WebAPI.Hmac,代码行数:8,代码来源:AuthenticateAttribute.cs


示例12: Getting_nonexistent_header_returns_default

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

            var nonexistent = headers.GetFirst<string>("nope");

            nonexistent.ShouldBeNull();
        }
开发者ID:jwynia,项目名称:stormpath-sdk-dotnet,代码行数:8,代码来源:HttpHeaders_tests.cs


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


示例14: WebClientHttpResponse

        /// <summary>
        /// Creates a new instance of <see cref="WebClientHttpResponse"/> 
        /// with the given <see cref="HttpWebResponse"/> instance.
        /// </summary>
        /// <param name="response">The <see cref="HttpWebResponse"/> instance to use.</param>
        public WebClientHttpResponse(HttpWebResponse response)
        {
            ArgumentUtils.AssertNotNull(response, "response");

            this.httpWebResponse = response;
            this.headers = new HttpHeaders();

            this.Initialize();
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:14,代码来源:WebClientHttpResponse.cs


示例15: DefaultResourceDataRequest

 public DefaultResourceDataRequest(ResourceAction action, Type resourceType, CanonicalUri uri, HttpHeaders requestHeaders, Map properties, bool skipCache)
 {
     this.action = action;
     this.uri = uri;
     this.requestHeaders = requestHeaders;
     this.resourceType = resourceType;
     this.properties = properties;
     this.skipCache = skipCache;
 }
开发者ID:ssankar1234,项目名称:stormpath-sdk-dotnet,代码行数:9,代码来源:DefaultResourceDataRequest.cs


示例16: DefaultHttpResponse

 public DefaultHttpResponse(int httpStatus, string responsePhrase, HttpHeaders headers, string body, string bodyContentType, bool transportError)
 {
     this.statusCode = httpStatus;
     this.responsePhrase = responsePhrase;
     this.headers = headers;
     this.body = body;
     this.bodyContentType = bodyContentType;
     this.transportError = transportError;
 }
开发者ID:jwynia,项目名称:stormpath-sdk-dotnet,代码行数:9,代码来源:DefaultHttpResponse.cs


示例17: WebRequestorResponse

 public WebRequestorResponse(Stream stream, HttpStatusCode httpStatusCode, HttpHeaders headers, string contentType)
 {
     ContentType = contentType;
     Stream = stream;
     HttpStatusCode = httpStatusCode;
     if (headers != null)
     {
         Headers = headers.ToDictionary(i => i.Key, i => string.Join(";", i.Value));
     }
 }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:10,代码来源:HttpClientExtensions.cs


示例18: MapResponseHeaders

		private static IDictionary<string, string> MapResponseHeaders(HttpHeaders headerCollection)
		{
			var resultHeaders = new Dictionary<string, string>();

			foreach (var header in headerCollection)
			{
				resultHeaders.Add(header.Key, string.Join(",", header.Value));
			}

			return resultHeaders;
		}
开发者ID:DrValani,项目名称:SevenDigital.Api.Wrapper,代码行数:11,代码来源:HttpClientMediator.cs


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


示例20: ODataMessageWrapper

 public ODataMessageWrapper(Stream stream, HttpHeaders headers)
 {
     _stream = stream;
     if (headers != null)
     {
         _headers = headers.ToDictionary(kvp => kvp.Key, kvp => String.Join(";", kvp.Value));
     }
     else
     {
         _headers = new Dictionary<string, string>();
     }
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:12,代码来源:ODataMessageWrapper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# HttpHelper类代码示例发布时间:2022-05-24
下一篇:
C# HttpHeaderValueCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap