WebResponse.Headers 속성
파생 클래스에서 재정의될 때, 요청과 연결된 헤더 이름/값 쌍의 컬렉션을 가져옵니다.
네임스페이스: System.Net
어셈블리: System(system.dll)
구문
‘선언
Public Overridable ReadOnly Property Headers As WebHeaderCollection
‘사용 방법
Dim instance As WebResponse
Dim value As WebHeaderCollection
value = instance.Headers
public virtual WebHeaderCollection Headers { get; }
public:
virtual property WebHeaderCollection^ Headers {
WebHeaderCollection^ get ();
}
/** @property */
public WebHeaderCollection get_Headers ()
public function get Headers () : WebHeaderCollection
속성 값
이 응답과 관련된 헤더 값을 포함하는 WebHeaderCollection 클래스의 인스턴스입니다.
예외
예외 형식 | 조건 |
---|---|
속성이 하위 클래스에서 재정의되지 않았는데 속성을 가져오거나 설정하려 할 경우 |
설명
Headers 속성에는 이 응답에서 반환된 헤더 이름/값 쌍이 들어 있습니다.
참고
WebResponse 클래스는 abstract 클래스입니다. 런타임에서 WebResponse 인스턴스의 실제 동작은 WebRequest.GetResponse가 반환한 하위 클래스에 의해 결정됩니다. 기본값과 예외에 대한 자세한 내용은 HttpWebResponse나 FileWebResponse와 같은 하위 클래스에 대한 설명서를 참조하십시오.
예제
다음 예제에서는 WebResponse에서 반환된 헤더 이름/값 쌍을 모두 표시합니다.
' 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()
// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create("https://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.
WebRequest^ myWebRequest = WebRequest::Create( "https://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("https://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.get_Headers().get_Count(); ++i) {
Console.WriteLine("\nHeader Name:{0}, Header value :{1}",
myWebResponse.get_Headers().get_Keys().get_Item(i),
myWebResponse.get_Headers().get_Item(i));
}
// Release resources of response object.
myWebResponse.Close();
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
WebResponse 클래스
WebResponse 멤버
System.Net 네임스페이스
WebHeaderCollection 클래스
HttpWebResponse.Headers 속성