HttpWebResponse.Headers プロパティ
アセンブリ: System (system.dll 内)

/** @property */ public WebHeaderCollection get_Headers ()
応答で返されるヘッダー情報を格納する WebHeaderCollection。


Headers プロパティは、応答で返される HTTP ヘッダー値を格納する名前/値ペアのコレクションです。インターネット リソースから返される共通ヘッダー情報は、HttpWebResponse クラスのプロパティとして公開されます。API がプロパティとして公開する共通ヘッダーの一覧を次の表に示します。
Content-Encoding | ContentEncoding |
Content-Length | ContentLength |

すべての応答ヘッダーの内容をコンソールに出力する例を次に示します。
' Creates an HttpWebRequest with the specified URL. Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest) ' Sends the HttpWebRequest and waits for a response. Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse) ' Displays all the Headers present in the response received from the URI. Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The following headers were received in the response") 'The Headers property is a WebHeaderCollection. Use it's properties to traverse the collection and display each header. Dim i As Integer While i < myHttpWebResponse.Headers.Count Console.WriteLine(ControlChars.Cr + "Header Name:{0}, Value :{1}", myHttpWebResponse.Headers.Keys(i), myHttpWebResponse.Headers(i)) i = i + 1 End While myHttpWebResponse.Close()
// Creates an HttpWebRequest for the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); // Sends the HttpWebRequest and waits for response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); // Displays all the headers present in the response received from the URI. Console.WriteLine("\r\nThe following headers were received in the response:"); // Displays each header and it's key associated with the response. for(int i=0; i < myHttpWebResponse.Headers.Count; ++i) Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]); // Releases the resources of the response. myHttpWebResponse.Close();
// Creates an HttpWebRequest for the specified URL. HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( url )); // Sends the HttpWebRequest and waits for response. HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse()); // Displays all the headers present in the response received from the URI. Console::WriteLine( "\r\nThe following headers were received in the response:" ); // Displays each header and its key associated with the response. for ( int i = 0; i < myHttpWebResponse->Headers->Count; ++i ) Console::WriteLine( "\nHeader Name: {0}, Value : {1}", myHttpWebResponse->Headers->Keys[ i ], myHttpWebResponse->Headers[ (System::Net::HttpRequestHeader)i ] ); // Releases the resources of the response. myHttpWebResponse->Close();
// Creates an HttpWebRequest for the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url); // Sends the HttpWebRequest and waits for response. HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse(); // Displays all the headers present in the response // received from the URI. Console.WriteLine("\r\nThe following headers were received" + " in the response:"); // Displays each header and it's key associated with the response. for (int i = 0; i < myHttpWebResponse.get_Headers().get_Count(); ++i) { Console.WriteLine("\nHeader Name:{0}, Value :{1}", myHttpWebResponse.get_Headers().get_Keys().get_Item(i), myHttpWebResponse.get_Headers().get_Item(i)); } // Releases the resources of the response. myHttpWebResponse.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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpWebResponse.Headers プロパティを検索する場合は、下記のリンクをクリックしてください。

- HttpWebResponse.Headers プロパティのページへのリンク