WebResponse.Headers 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의될 때, 요청과 연결된 헤더 이름/값 쌍의 컬렉션을 가져옵니다.
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에 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 다음과 같은 HttpWebResponse FileWebResponse하위 클래스에 대한 설명서를 참조하세요.