HttpWebRequest.Headers プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpWebRequest.Headers プロパティの意味・解説 

HttpWebRequest.Headers プロパティ

HTTP ヘッダー構成する名前と値のペアコレクション指定します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Property
 Headers As WebHeaderCollection
Dim instance As HttpWebRequest
Dim value As WebHeaderCollection

value = instance.Headers

instance.Headers = value
public override WebHeaderCollection Headers { get;
 set; }
public:
virtual property WebHeaderCollection^ Headers {
    WebHeaderCollection^ get () override;
    void set (WebHeaderCollection^ value) override;
}
/** @property */
public WebHeaderCollection get_Headers ()

/** @property */
public void set_Headers (WebHeaderCollection
 value)
public override function get
 Headers () : WebHeaderCollection

public override function set
 Headers (value : WebHeaderCollection)

プロパティ
HTTP 要求ヘッダー構成する名前と値のペア格納している WebHeaderCollection。

例外例外
例外種類条件

InvalidOperationException

要求が GetRequestStream、BeginGetRequestStream、GetResponse、または BeginGetResponse の各メソッド呼び出しによって開始されました。

解説解説

Headers コレクションは、要求関連付けられているプロトコル ヘッダー格納しますHeaders コレクションには格納されず、システムプロパティ、またはメソッドいずれか設定される HTTP ヘッダーの一覧を次の表に示します

これらの保護されヘッダー1 つ設定しようとすると、Add メソッドは ArgumentException をスローます。

GetRequestStreamBeginGetRequestStreamGetResponse、または BeginGetResponse の各メソッド呼び出しによって開始した要求の後に Headers プロパティ変更すると、InvalidOperationExceptionスローさます。

Web サーバーおよびキャッシュにより、Web 要求ヘッダー変更されたり追加されたりすることがあるため、ヘッダーの値は変わることがあります

使用例使用例

HTTP ヘッダーの名前と値のペアを、Headers プロパティ使用してコンソール出力するコード例次に示します

     ' Create a new 'HttpWebRequest' Object to the mentioned URL.
     Dim myHttpWebRequest As HttpWebRequest
 = CType(WebRequest.Create("http://www.contoso.com"),
 HttpWebRequest)
     ' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse'
 variable.
     Dim myHttpWebResponse As HttpWebResponse
 = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
     Console.WriteLine(ControlChars.Cr + "The HttpHeaders are
 " + ControlChars.Cr + ControlChars.Cr + ControlChars.Tab + "Name"
 + ControlChars.Tab + ControlChars.Tab + "Value" + ControlChars.Cr + "{0}", myHttpWebRequest.Headers)

     ' Print the HTML contents of the page to the console. 
     Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
     Dim streamRead As New
 StreamReader(streamResponse)
     Dim readBuff(256) As [Char]
     Dim count As Integer
 = streamRead.Read(readBuff, 0, 256)
     Console.WriteLine(ControlChars.Cr + "The HTML contents of
 page the are  : " + ControlChars.Cr + ControlChars.Cr + "
 ")
     While count > 0
         Dim outputData As New
 [String](readBuff, 0, count)
         Console.Write(outputData)
         count = streamRead.Read(readBuff, 0, 256)
     End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
' Release the HttpWebResponse Resource.
 myHttpWebResponse.Close()
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse'
 variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",myHttpWebRequest.Headers);
// Print the HTML contents of the page to the console. 
Stream streamResponse=myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader( streamResponse );
Char[] readBuff = new Char[256];
int count = streamRead.Read( readBuff, 0, 256 );
Console.WriteLine("\nThe HTML contents of page the are  : \n\n ");    
while (count > 0) 
{
    String outputData = new String(readBuff, 0, count);
    Console.Write(outputData);
    count = streamRead.Read(readBuff, 0, 256);
}
// Close the Stream object.
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse Resource.
myHttpWebResponse.Close();
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com"
 ) );
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse'
 variable.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse()
 );
Console::WriteLine( "\nThe HttpHeaders are \n\n\tName\t\tValue\n {0}",
 myHttpWebRequest->Headers );
// Print the HTML contents of the page to the console.
Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
StreamReader^ streamRead = gcnew StreamReader( streamResponse );
array<Char>^ readBuff = gcnew array<Char>(256);
int count = streamRead->Read( readBuff, 0, 256 );
Console::WriteLine( "\nThe HTML contents of page the are  : \n\n " );
while ( count > 0 )
{
   String^ outputData = gcnew String( readBuff,0,count );
   Console::Write( outputData );
   count = streamRead->Read( readBuff, 0, 256 );
}
streamResponse->Close();
streamRead->Close();
// Release the HttpWebResponse Resource.
myHttpWebResponse->Close();
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
    (WebRequest.Create("http://www.contoso.com"));

// Assign the response object of 'HttpWebRequest' to a 
//'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
    (myHttpWebRequest.GetResponse());
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
    myHttpWebRequest.get_Headers());
// Print the HTML contents of the page to the console. 
Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
char readBuff[] = new char[256];
int count = streamRead.Read(readBuff, 0, 256);
Console.WriteLine("\nThe HTML contents of page the are  : \n\n ");
while (count > 0) {
    String outputData = new String(readBuff, 0, count);
    Console.Write(outputData);
    count = streamRead.Read(readBuff, 0, 256);
}

// Close the Stream object.
streamResponse.Close();
streamRead.Close();

// Release the HttpWebResponse Resource.
myHttpWebResponse.Close();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpWebRequest.Headers プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpWebRequest.Headers プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpWebRequest.Headers プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HttpWebRequest.Headers プロパティ」の関連用語

HttpWebRequest.Headers プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpWebRequest.Headers プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS