HttpResponseHeaderCollection 클래스

정의

HTTP 응답과 연결된 HTTP 헤더의 컬렉션을 제공합니다.

public ref class HttpResponseHeaderCollection sealed : IIterable<IKeyValuePair<Platform::String ^, Platform::String ^> ^>, IMap<Platform::String ^, Platform::String ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpResponseHeaderCollection final : IIterable<IKeyValuePair<winrt::hstring, winrt::hstring const&>>, IMap<winrt::hstring, winrt::hstring const&>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpResponseHeaderCollection final : IIterable<IKeyValuePair<winrt::hstring, winrt::hstring const&>>, IMap<winrt::hstring, winrt::hstring const&>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpResponseHeaderCollection : IDictionary<string,string>, IEnumerable<KeyValuePair<string,string>>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpResponseHeaderCollection : IDictionary<string,string>, IEnumerable<KeyValuePair<string,string>>, IStringable
Public NotInheritable Class HttpResponseHeaderCollection
Implements IDictionary(Of String, String), IEnumerable(Of KeyValuePair(Of String, String)), IStringable
상속
Object Platform::Object IInspectable HttpResponseHeaderCollection
특성
구현
IDictionary<String,String> IMap<Platform::String,Platform::String> IMap<winrt::hstring,winrt::hstring> IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IEnumerable<KeyValuePair<String,String>> IIterable<IKeyValuePair<Platform::String,Platform::String>> IIterable<IKeyValuePair<winrt::hstring,winrt::hstring>> IStringable

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 샘플 코드에서는 HttpResponseHeaderCollection 개체의 속성을 사용하여 HttpResponseMessage 개체에서 응답 헤더를 가져와서 설정하는 메서드를 보여 줍니다. Windows.Web.Http.Headers 네임스페이스에는 유효성 검사를 사용하여 헤더를 가져와서 설정하는 데 사용할 수 있는 특정 HTTP 헤더에 대한 강력한 형식의 헤더 컬렉션 및 값 클래스가 많이 있습니다.

using System;
using System.Collections.Generic;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        void DemonstrateResponseHeaders() {

            DemonstrateHeaderResponseAge();
            DemonstrateHeaderResponseAllow();
            DemonstrateHeaderResponseCacheControl();
            DemonstrateHeaderResponseDate();
            DemonstrateHeaderResponseLocation();
            DemonstrateHeaderResponseProxyAuthenticate();

        }


        public void DemonstrateHeaderResponseAge()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            DateTimeOffset value = DateTimeOffset.UtcNow;
            response.Headers.Age = new TimeSpan(1, 35, 55); // 1 hour, 35 minutes, 55 seconds.

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Age value in minutes: {0}", response.Headers.Age.Value.TotalMinutes);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Age ToString() results: {0}", response.Headers.Age.ToString());
        }


        public void DemonstrateHeaderResponseAllow()
        {
            var response = new HttpResponseMessage();

            // Set the header with a string
            response.Headers.Allow.TryParseAdd ("GET");

            // Set the header with a strong type
            response.Headers.Allow.Add(HttpMethod.Patch);

            // Get the strong type out
            foreach (var value in response.Headers.Allow)
            {
                System.Diagnostics.Debug.WriteLine("Allow value: {0}", value.Method);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Allow ToString() results: {0}", response.Headers.Allow.ToString());
        }

        public void DemonstrateHeaderResponseCacheControl()
        {
            var response = new HttpResponseMessage();

            // Set the header with a string
            response.Headers.CacheControl.TryParseAdd("public");

            // Set the header with a strong type
            response.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "30"));

            // Get the strong type out
            foreach (var value in response.Headers.CacheControl)
            {
                System.Diagnostics.Debug.WriteLine("CacheControl {0}={1}", value.Name, value.Value);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The CacheControl ToString() results: {0}", response.Headers.CacheControl.ToString());
        }

        public void DemonstrateHeaderResponseDate()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.Date = DateTimeOffset.UtcNow;

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Date value in ticks: {0}", response.Headers.Date.Value.Ticks);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Date ToString() results: {0}", response.Headers.Date.ToString());
        }

        public void DemonstrateHeaderResponseLocation()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.Location = new Uri("http://example.com/");

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Location absolute uri: {0}", response.Headers.Location.AbsoluteUri);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Location ToString() results: {0}", response.Headers.Location.ToString());
        }

        public void DemonstrateHeaderResponseProxyAuthenticate()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.ProxyAuthenticate.TryParseAdd("Basic");
            response.Headers.ProxyAuthenticate.Add(new HttpChallengeHeaderValue("authScheme", "authToken"));

            // Get the strong type out
            foreach (var value in response.Headers.ProxyAuthenticate)
            {
                System.Diagnostics.Debug.WriteLine("Proxy authenticate scheme and token: {0} {1}", value.Scheme, value.Token);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The ProxyAuthenticate ToString() results: {0}", response.Headers.ProxyAuthenticate.ToString());
        }

        public void DemonstrateHeaderResponseRetryAfter()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            HttpDateOrDeltaHeaderValue newvalue;
            bool parseOk = HttpDateOrDeltaHeaderValue.TryParse("", out newvalue);
            if (parseOk)
            {
                response.Headers.RetryAfter = newvalue;
            }

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Date value in ticks: {0}", response.Headers.Date.Value.Ticks);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Date ToString() results: {0}", response.Headers.Date.ToString());
        }

설명

HttpResponseHeaderCollection은 HTTP 요청 메시지에 대한 HTTP 응답과 연결된 HTTP 헤더의 컬렉션입니다. HttpResponseHeaderCollection 개체를 사용하여 HTTP 응답에서 특정 헤더를 얻거나 설정할 수 있습니다. HttpResponseHeaderCollection 개체의 대부분의 속성은 특정 HTTP 헤더 값에 대한 액세스를 제공합니다.

HttpResponseMessageHeaders 속성은 HttpResponseHeaderCollection 개체를 반환합니다. HttpResponseHeaderCollection이 생성되는 방법입니다.

C# 또는 Microsoft Visual Basic에서 컬렉션 열거

C# 또는 Microsoft Visual Basic에서 HttpResponseHeaderCollection 개체를 반복할 수 있습니다. foreach 구문 사용과 같은 대부분의 경우 컴파일러는 이 캐스팅을 수행하므로 명시적으로 캐스팅 IEnumerable 할 필요가 없습니다. 예를 들어 GetEnumerator를 호출하려는 경우 명시적으로 캐스팅해야 하는 경우 컬렉션 개체를 제약 조건으로 StringStringKeyValuePair를 사용하여 IEnumerable<T>로 캐스팅합니다.

속성

Age

HTTP 응답에서 Age HTTP 헤더의 값을 나타내는 TimeSpan 개체를 가져오거나 설정합니다.

Allow

HTTP 응답에서 HTTP 헤더 허용 값을 나타내는 HttpMethod 개체의 HttpMethodHeaderValueCollection을 가져옵니다.

CacheControl

HTTP 응답에서 Cache-Control HTTP 헤더의 값을 나타내는 개체의 HttpCacheDirectiveHeaderValueCollection을 가져옵니다.

Connection

HTTP 응답에서 연결 HTTP 헤더의 값을 나타내는 HttpConnectionOptionHeaderValue 개체의 HttpConnectionOptionHeaderValueCollection을 가져옵니다.

Date

HTTP 응답에서 Date HTTP 헤더의 값을 나타내는 DateTime 개체를 가져오거나 설정합니다.

Location

HTTP 응답에서 값 또는 위치 HTTP 헤더를 나타내는 Uri를 가져오거나 설정합니다.

ProxyAuthenticate

HTTP 응답에서 Proxy-Authenticate HTTP 헤더의 값을 나타내는 HttpChallengeHeaderValue 개체의 HttpChallengeHeaderValueCollection을 가져옵니다.

RetryAfter

HTTP 응답에서 Retry-After HTTP 헤더의 값을 나타내는 HttpDateOrDeltaHeaderValue 개체를 가져오거나 설정합니다.

Size

HttpResponseHeaderCollection의 개체 수를 가져옵니다.

TransferEncoding

HTTP 응답에서 Transfer-Encoding HTTP 헤더의 값을 나타내는 HttpTransferCodingHeaderValue 개체의 HttpTransferCodingHeaderValueCollection을 가져옵니다.

WwwAuthenticate

HTTP 응답에서 WWW-Authenticate HTTP 헤더의 값을 나타내는 HttpChallengeHeaderValue 개체의 HttpChallengeHeaderValueCollection을 가져옵니다.

메서드

Append(String, String)

HttpResponseHeaderCollection의 끝에 새 항목을 추가합니다.

Clear()

컬렉션에서 모든 개체를 제거합니다.

First()

HttpResponseHeaderCollection의 첫 번째 항목에 대한 반복기를 검색합니다.

GetView()

HttpResponseHeaderCollection의 변경할 수 없는 보기를 반환합니다.

HasKey(String)

HttpResponseHeaderCollection에 지정된 키가 포함되어 있는지 여부를 확인합니다.

Insert(String, String)

HttpResponseHeaderCollection의 항목을 지정된 키 및 값으로 삽입하거나 바꿉니다.

Lookup(String)

HttpResponseHeaderCollection에서 항목을 조회합니다.

Remove(String)

HttpResponseHeaderCollection에서 지정된 키가 있는 항목을 제거합니다.

ToString()

현재 HttpResponseHeaderCollection 개체를 나타내는 문자열을 반환합니다.

TryAppendWithoutValidation(String, String)

유효성 검사 없이 HttpResponseHeaderCollection 에 지정된 항목을 추가해 보세요.

적용 대상

추가 정보