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 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決定されます。 既定値と例外の詳細については、 や FileWebResponseなどのHttpWebResponse子孫クラスのドキュメントを参照してください。