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

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

WebClient.Headers プロパティ

要求関連付けられているヘッダーの名前/値ペアコレクション取得または設定します

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

Public Property Headers As
 WebHeaderCollection
Dim instance As WebClient
Dim value As WebHeaderCollection

value = instance.Headers

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

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

public function set Headers
 (value : WebHeaderCollection)

プロパティ
要求関連付けられているヘッダーの名前/値ペア格納する WebHeaderCollection。

解説解説

Headers プロパティは、WebClient が要求送信するヘッダー情報を含む WebHeaderCollection インスタンス格納します。これは無制限ヘッダーコレクションであるため、HttpWebRequest などの WebRequest の子孫で制限されるヘッダー設定できます

使用例使用例

Headers コレクション使用してHTTP Content-Type ヘッダーapplication/x-www-form-urlencoded,設定しフォーム データポスト追加されたことをサーバー通知するコード例次に示します

Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post
 data to{for example, http://www.contoso.com} : ")
uriString = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to
 be posted to the URI {0}:", uriString)
Dim postData As String =
 Console.ReadLine()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte()
 = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte()
 = myWebClient.UploadData(uriString, "POST", byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}",
 Encoding.ASCII.GetString(responseArray))
string uriString;
Console.Write("\nPlease enter the URI to post data to {for
 example, http://www.contoso.com} : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:"
,uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...",  uriString);                
        
// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
// Decode and display the response.
Console.WriteLine("\nResponse received was {0}",
    Encoding.ASCII.GetString(responseArray));
String^ uriString;
Console::Write( "\nPlease enter the URI to post data to {for
 example, http://www.contoso.com}: " );
uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:",
 uriString );
String^ postData = Console::ReadLine();
myWebClient->Headers->Add( "Content-Type", "application/x-www-form-urlencoded"
 );
// Apply ASCII Encoding to obtain the String^ as a Byte array.
array<Byte>^ byteArray = Encoding::ASCII->GetBytes( postData );
Console::WriteLine( "Uploading to {0} ...", uriString );
// Upload the input String* using the HTTP 1.0 POST method.
array<Byte>^responseArray = myWebClient->UploadData( uriString, "POST",
 byteArray );
// Decode and display the response.
Console::WriteLine( "\nResponse received was {0}",
   Encoding::ASCII->GetString( responseArray ) );
String uriString;
Console.Write("\nPlease enter the URI to post data to {" 
    + "for example, http://www.contoso.com}
 : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the" 
    + " URI {0}:", uriString);
String postData = Console.ReadLine();
myWebClient.get_Headers().Add("Content-Type",
    "application/x-www-form-urlencoded");
// Apply ASCII Encoding to obtain the string as a byte array.
ubyte byteArray[] = Encoding.get_ASCII().GetBytes(postData);
Console.WriteLine("Uploading to {0} ...", uriString);
// Upload the input string using the HTTP 1.0 POST method.
ubyte responseArray[] = myWebClient.UploadData(uriString, "POST",
    byteArray);
// Decode and display the response.
Console.WriteLine("\nResponse received was {0}", Encoding.
    get_ASCII().GetString(responseArray));
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebClient クラス
WebClient メンバ
System.Net 名前空間
WebRequest.Headers
HttpWebRequest.Headers プロパティ


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS