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

Dim instance As WebClient Dim value As WebHeaderCollection value = instance.Headers instance.Headers = value
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));

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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

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