次の方法で共有


WebClient.ResponseHeaders プロパティ

応答に関連付けられているヘッダーの名前/値ペアのコレクションを取得します。

Public ReadOnly Property ResponseHeaders As WebHeaderCollection
[C#]
public WebHeaderCollection ResponseHeaders {get;}
[C++]
public: __property WebHeaderCollection* get_ResponseHeaders();
[JScript]
public function get ResponseHeaders() : WebHeaderCollection;

プロパティ値

応答に関連付けられているヘッダーの名前/値ペアを格納する WebHeaderCollection

解説

ResponseHeaders プロパティは、 WebClient がインターネット リソースから受信するヘッダー情報を含む WebHeaderCollection インスタンスを格納します。

使用例

[Visual Basic, C#, C++] サーバーが返した ResponseHeaders をダウンロードし、表示する例を次に示します。

 
' 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 

[C#] 
// 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));

[C++] 
// Obtain the WebHeaderCollection instance containing the header name/value pair from the response.
WebHeaderCollection* myWebHeaderCollection = myWebClient->ResponseHeaders;
Console::WriteLine(S"\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 (S"\t {0} = {1}", myWebHeaderCollection->GetKey(i), myWebHeaderCollection->Get(i));

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

WebClient クラス | WebClient メンバ | System.Net 名前空間