다음을 통해 공유


WebClient.ResponseHeaders 속성

정의

응답과 연결된 헤더 이름/값 쌍의 컬렉션을 가져옵니다.

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

속성 값

응답과 연결된 헤더 이름/값 쌍을 포함하는 WebHeaderCollection, 응답이 수신되지 않은 경우 null.

예제

다음 코드 예제에서는 다운로드 하 고 서버에서 반환 된 ResponseHeaders 표시 합니다.

// Obtain the WebHeaderCollection instance containing the header name/value pair from the response.
WebHeaderCollection^ myWebHeaderCollection = myWebClient->ResponseHeaders;
Console::WriteLine( "\nDisplaying the response headers\n" );

// Loop through the ResponseHeaders and display the header name/value pairs.
for ( int i = 0; i < myWebHeaderCollection->Count; i++ )
{
   Console::WriteLine( "\t{0} = {1}", myWebHeaderCollection->GetKey( i ),
      myWebHeaderCollection->Get( i ) );
}
// Obtain the WebHeaderCollection instance containing the header name/value pair from the response.
WebHeaderCollection myWebHeaderCollection = myWebClient.ResponseHeaders;
Console.WriteLine("\nDisplaying the response headers\n");
// Loop through the ResponseHeaders and display the header name/value pairs.
for (int i=0; i < myWebHeaderCollection.Count; i++)				
    Console.WriteLine ("\t" + myWebHeaderCollection.GetKey(i) + " = " + myWebHeaderCollection.Get(i));
' ResponseHeaders is a WebHeaderCollection instance that contains the headers sent back 
 ' in response to the WebClient request. 
Dim myWebHeaderCollection As WebHeaderCollection = myWebClient.ResponseHeaders
Console.WriteLine(ControlChars.Cr + "Displaying the response headers" + ControlChars.Cr)
' Loop through the ResponseHeaders.
Dim i As Integer
For i = 0 To myWebHeaderCollection.Count - 1
    ' Display the headers as name/value pairs.
    Console.WriteLine((ControlChars.Tab + myWebHeaderCollection.GetKey(i) + " " + ChrW(61) + " " + myWebHeaderCollection.Get(i)))
Next i 

설명

주의

WebRequest, HttpWebRequest, ServicePointWebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.

ResponseHeaders 속성에는 WebClient 응답과 함께 수신하는 헤더 정보가 포함된 WebHeaderCollection 인스턴스가 포함되어 있습니다.

적용 대상