다음을 통해 공유


WebResponse.Headers 속성

정의

파생 클래스에서 재정의될 때, 요청과 연결된 헤더 이름/값 쌍의 컬렉션을 가져옵니다.

public:
 virtual property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); };
public virtual System.Net.WebHeaderCollection Headers { get; }
member this.Headers : System.Net.WebHeaderCollection
Public Overridable ReadOnly Property Headers As WebHeaderCollection

속성 값

이 응답과 관련된 헤더 값을 포함하는 WebHeaderCollection 클래스의 인스턴스입니다.

예외

속성이 서브클래스에서 재정의되지 않았는데 속성을 가져오거나 설정하려 할 경우

예제

다음 예제에서는 에 반환된 모든 헤더 이름-값 쌍을 WebResponse표시합니다.

// Create a 'WebRequest' object with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );

// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Display all the Headers present in the response received from the URl.
Console::WriteLine( "\nThe following headers were received in the response" );

// Display each header and its key , associated with the response object.
for ( int i = 0; i < myWebResponse->Headers->Count; ++i )
   Console::WriteLine( "\nHeader Name: {0}, Header value : {1}", myWebResponse->Headers->Keys[ i ], myWebResponse->Headers[ i ] );

// Release resources of response object.
myWebResponse->Close();

    // Create a 'WebRequest' object with the specified url. 	
   WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 

   // Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

   // Display all the Headers present in the response received from the URl.
   Console.WriteLine("\nThe following headers were received in the response");

// Display each header and it's key , associated with the response object.
   for(int i=0; i < myWebResponse.Headers.Count; ++i)  
      Console.WriteLine("\nHeader Name:{0}, Header value :{1}",myWebResponse.Headers.Keys[i],myWebResponse.Headers[i]); 

   // Release resources of response object.
   myWebResponse.Close();

    ' Create a 'WebRequest' object with the specified url 	
    Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")
    
    ' Send the 'WebRequest' and wait for response.
    Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
    
    ' Display all the Headers present in the response received from the URl.
    Console.WriteLine(ControlChars.Cr + "The following headers were received in the response")
    
    ' Headers property is a 'WebHeaderCollection'. Use it's properties to traverse the collection and display each header
    Dim i As Integer
    
    While i < myWebResponse.Headers.Count
        Console.WriteLine(ControlChars.Cr + "Header Name:{0}, Header value :{1}", myWebResponse.Headers.Keys(i), myWebResponse.Headers(i))
i = i + 1
    End While

    ' Release resources of response object.
    myWebResponse.Close()

설명

속성은 Headers 응답에 반환된 이름-값 헤더 쌍을 포함합니다.

참고

클래스는 WebResponse 클래스입니다 abstract . 런타임에 인스턴스의 WebResponse 실제 동작은 에서 반환 WebRequest.GetResponse된 하위 클래스에 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 및 FileWebResponse와 같은 HttpWebResponse 하위 클래스에 대한 설명서를 참조하세요.

적용 대상

추가 정보