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


C# HttpHeaders类代码示例

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


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


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