다음을 통해 공유


HttpWebResponse.Headers 속성

정의

서버에서 이 응답과 관련된 헤더를 가져옵니다.

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

속성 값

응답과 함께 반환되는 헤더 정보를 포함하는 WebHeaderCollection입니다.

예외

현재 인스턴스가 삭제된 경우

예제

다음 예제에서는 모든 응답 헤더의 내용을 콘솔에 씁니다.

// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( url ));

// Sends the HttpWebRequest and waits for response.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());

// Displays all the headers present in the response received from the URI.
Console::WriteLine( "\r\nThe following headers were received in the response:" );

// Displays each header and its key associated with the response.
for ( int i = 0; i < myHttpWebResponse->Headers->Count; ++i )
   Console::WriteLine( "\nHeader Name: {0}, Value : {1}",
      myHttpWebResponse->Headers->Keys[ i ],
      myHttpWebResponse->Headers[ (System::Net::HttpRequestHeader)i ] );

// Releases the resources of the response.
myHttpWebResponse->Close();
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

// Displays all the headers present in the response received from the URI.
Console.WriteLine("\r\nThe following headers were received in the response:");
// Displays each header and it's key associated with the response.
for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)
    Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]);
// Releases the resources of the response.
myHttpWebResponse.Close();
' Creates an HttpWebRequest with the specified URL. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
' Sends the HttpWebRequest and waits for a response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Displays all the Headers present in the response received from the URI.
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The following headers were received in the response")
'The Headers property is a WebHeaderCollection. Use it's properties to traverse the collection and display each header.
Dim i As Integer
While i < myHttpWebResponse.Headers.Count
    Console.WriteLine(ControlChars.Cr + "Header Name:{0}, Value :{1}", myHttpWebResponse.Headers.Keys(i), myHttpWebResponse.Headers(i))
  i = i + 1
End While
myHttpWebResponse.Close()

설명

속성은 Headers 응답과 함께 반환된 HTTP 헤더 값을 포함하는 이름/값 쌍의 컬렉션입니다. 인터넷 리소스에서 반환된 공통 헤더 정보는 클래스의 HttpWebResponse 속성으로 노출됩니다. 다음 표에서는 API가 속성으로 노출하는 일반적인 헤더를 나열합니다.

헤더 속성
Content-Encoding ContentEncoding
Content-Length ContentLength
콘텐츠 형식 ContentType
Last-Modified LastModified
서버 Server

적용 대상