HttpListenerResponse.Headers 속성

정의

서버에서 반환되는 헤더 이름/값 쌍의 컬렉션을 가져오거나 설정합니다.

public:
 property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); void set(System::Net::WebHeaderCollection ^ value); };
public System.Net.WebHeaderCollection Headers { get; set; }
member this.Headers : System.Net.WebHeaderCollection with get, set
Public Property Headers As WebHeaderCollection

속성 값

응답에 포함되도록 명시적으로 설정된 모든 HTTP 헤더가 들어 있는 WebHeaderCollection 인스턴스입니다.

예외

set 작업에 지정된 WebHeaderCollection 인스턴스가 응답에 대해 올바르지 않은 경우

예제

다음 코드 예제에서는 에 헤더를 표시 하는 방법을 WebHeaderCollection보여 줍니다.

    // Displays the header information that accompanied a request.
public static void DisplayWebHeaderCollection(HttpListenerResponse response)
{
    WebHeaderCollection headers = response.Headers;
    // Get each header and display each value.
    foreach (string key in headers.AllKeys)
    {
        string[] values = headers.GetValues(key);
        if(values.Length > 0)
        {
            Console.WriteLine("The values of the {0} header are: ", key);
            foreach (string value in values)
            {
                Console.WriteLine("   {0}", value);
            }
        }
        else
        {
            Console.WriteLine("There is no value associated with the header.");
        }
    }
}
' Displays the header information that accompanied a request.
Public Shared Sub DisplayWebHeaderCollection(ByVal response As HttpListenerResponse)
    Dim headers As WebHeaderCollection = response.Headers

    ' Get each header and display each value.
    For Each key As String In headers.AllKeys
        Dim values As String() = headers.GetValues(key)

        If values.Length > 0 Then
            Console.WriteLine("The values of the {0} header are: ", key)

            For Each value As String In values
                Console.WriteLine("   {0}", value)
            Next
        Else
            Console.WriteLine("There is no value associated with the header.")
        End If
    Next
End Sub

설명

응답 헤더에는 응답 날짜 및 시간, 응답 서버의 ID 및 응답 본문에 포함된 데이터의 MIME 형식과 같은 메타데이터 정보가 포함됩니다.

응답 헤더의 전체 목록은 열거형을 HttpResponseHeader 참조하세요.

참고

Headers 속성을 사용하여 Content-Length, Keep-Alive, Transfer-Encoding 또는 WWW-Authenticate 헤더를 설정하려고 하면 예외가 throw됩니다. KeepAlive 또는 ContentLength64 속성을 사용하여 이러한 헤더를 설정합니다. Transfer-Encoding 또는 WWW-Authenticate 헤더를 수동으로 설정할 수 없습니다.

적용 대상

추가 정보