WebClient.UploadValues メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した URI を持つリソースへ名前/値コレクションをアップロードします。
オーバーロード
UploadValues(String, NameValueCollection) |
指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。 |
UploadValues(Uri, NameValueCollection) |
指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。 |
UploadValues(String, String, NameValueCollection) |
指定したメソッドを使用して、指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。 |
UploadValues(Uri, String, NameValueCollection) |
指定したメソッドを使用して、指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。 |
UploadValues(String, NameValueCollection)
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。
public:
cli::array <System::Byte> ^ UploadValues(System::String ^ address, System::Collections::Specialized::NameValueCollection ^ data);
public byte[] UploadValues (string address, System.Collections.Specialized.NameValueCollection data);
member this.UploadValues : string * System.Collections.Specialized.NameValueCollection -> byte[]
Public Function UploadValues (address As String, data As NameValueCollection) As Byte()
パラメーター
- address
- String
コレクションを受信するリソースの URI。
- data
- NameValueCollection
リソースに送信する NameValueCollection。
戻り値
リソースからの応答の本文を格納している Byte 配列。
例外
BaseAddress および address
を組み合わせて形成された URI が無効です。
- または -
data
は null
です。
- または -
リソースをホストしているサーバーから応答がありませんでした。
- または -
ストリームのオープン中にエラーが発生しました。
- または -
Content-type
ヘッダーが null
または "application/x-www-form-urlencoded" ではありません。
例
次のコード例では、ユーザー (名前、年齢、住所) から情報を収集し、 を使用して UploadValues値をサーバーに投稿します。 サーバーからの応答がコンソールに表示されます。
Console::Write( "\nPlease enter the URI to post data to: " );
String^ uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection^ myNameValueCollection = gcnew NameValueCollection;
Console::WriteLine( "Please enter the following parameters to be posted to the URL" );
Console::Write( "Name: " );
String^ name = Console::ReadLine();
Console::Write( "Age: " );
String^ age = Console::ReadLine();
Console::Write( "Address: " );
String^ address = Console::ReadLine();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add( "Name", name );
myNameValueCollection->Add( "Address", address );
myNameValueCollection->Add( "Age", age );
Console::WriteLine( "\nUploading to {0} ...", uriString );
// 'The Upload(String, NameValueCollection)' implicitly method sets HTTP POST as the request method.
array<Byte>^ responseArray = myWebClient->UploadValues( uriString, myNameValueCollection );
// Decode and display the response.
Console::WriteLine( "\nResponse received was :\n {0}", Encoding::ASCII->GetString( responseArray ) );
Console.Write("\nPlease enter the URI to post data to : ");
string uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();
Console.WriteLine("Please enter the following parameters to be posted to the URL");
Console.Write("Name:");
string name = Console.ReadLine();
Console.Write("Age:");
string age = Console.ReadLine();
Console.Write("Address:");
string address = Console.ReadLine();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);
Console.WriteLine("\nUploading to {0} ...", uriString);
// 'The Upload(String,NameValueCollection)' implicitly method sets HTTP POST as the request method.
byte[] responseArray = myWebClient.UploadValues(uriString,myNameValueCollection);
// Decode and display the response.
Console.WriteLine("\nResponse received was :\n{0}",Encoding.ASCII.GetString(responseArray));
Console.Write(ControlChars.Cr + "Please enter the URI to post data to : ")
Dim uriString As String = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection()
Console.WriteLine("Please enter the following parameters to be posted to the URL:")
Console.Write("Name:")
Dim name As String = Console.ReadLine()
Console.Write("Age:")
Dim age As String = Console.ReadLine()
Console.Write("Address:")
Dim address As String = Console.ReadLine()
' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)
Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...", uriString)
' The Upload(String,NameValueCollection)' method implicitly sets the HTTP POST as the request method.
Dim responseArray As Byte() = myWebClient.UploadValues(uriString, myNameValueCollection)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :" + ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))
注釈
メソッドは UploadValues 、 を NameValueCollection サーバーに送信します。 このメソッドは、データのアップロード中にブロックします。 サーバーの応答を待機しながら実行を続行するには、いずれかのメソッドを UploadValuesAsync 使用します。
基になる要求がサーバーによって認識されない場合、基になるプロトコル クラスによって何が発生するかが決まります。 通常、 WebException は、エラーを示すために プロパティが Status 設定された状態でスローされます。
Content-type ヘッダーが の場合、UploadValuesメソッドはそれを null
"application/x-www-form-urlencoded" に設定します。
プロパティが空の BaseAddress 文字列 ("") address
ではなく、絶対 URI を含まない場合は、 address
と組み合わせて BaseAddress 要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが QueryString 空の文字列でない場合は、 に address
追加されます。
このメソッドでは、STOR コマンドを使用して FTP リソースをアップロードします。 HTTP リソースの場合は、POST メソッドが使用されます。
Note
このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「 .NET Framework でのネットワーク トレース」を参照してください。
適用対象
UploadValues(Uri, NameValueCollection)
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。
public:
cli::array <System::Byte> ^ UploadValues(Uri ^ address, System::Collections::Specialized::NameValueCollection ^ data);
public byte[] UploadValues (Uri address, System.Collections.Specialized.NameValueCollection data);
member this.UploadValues : Uri * System.Collections.Specialized.NameValueCollection -> byte[]
Public Function UploadValues (address As Uri, data As NameValueCollection) As Byte()
パラメーター
- address
- Uri
コレクションを受信するリソースの URI。
- data
- NameValueCollection
リソースに送信する NameValueCollection。
戻り値
リソースからの応答の本文を格納している Byte 配列。
例外
BaseAddress および address
を組み合わせて形成された URI が無効です。
- または -
data
は null
です。
- または -
リソースをホストしているサーバーから応答がありませんでした。
- または -
ストリームのオープン中にエラーが発生しました。
- または -
Content-type
ヘッダーが null
または "application/x-www-form-urlencoded" ではありません。
注釈
メソッドは UploadValues 、 を NameValueCollection サーバーに送信します。 このメソッドは、データのアップロード中にブロックします。 サーバーの応答を待機しながら実行を続行するには、いずれかのメソッドを UploadValuesAsync 使用します。
基になる要求がサーバーによって認識されない場合、基になるプロトコル クラスによって何が発生するかが決まります。 通常、 WebException は、エラーを示すために プロパティが Status 設定された状態でスローされます。
Content-type ヘッダーが の場合、UploadValuesメソッドはそれを null
"application/x-www-form-urlencoded" に設定します。
プロパティが空の BaseAddress 文字列 ("") address
ではなく、絶対 URI を含まない場合は、 address
と組み合わせて BaseAddress 要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが QueryString 空の文字列でない場合は、 に address
追加されます。
このメソッドでは、STOR コマンドを使用して FTP リソースをアップロードします。 HTTP リソースの場合は、POST メソッドが使用されます。
Note
このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「 .NET Framework でのネットワーク トレース」を参照してください。
適用対象
UploadValues(String, String, NameValueCollection)
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
指定したメソッドを使用して、指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。
public:
cli::array <System::Byte> ^ UploadValues(System::String ^ address, System::String ^ method, System::Collections::Specialized::NameValueCollection ^ data);
public byte[] UploadValues (string address, string? method, System.Collections.Specialized.NameValueCollection data);
public byte[] UploadValues (string address, string method, System.Collections.Specialized.NameValueCollection data);
member this.UploadValues : string * string * System.Collections.Specialized.NameValueCollection -> byte[]
Public Function UploadValues (address As String, method As String, data As NameValueCollection) As Byte()
パラメーター
- address
- String
コレクションを受信するリソースの URI。
- method
- String
リソースにファイルを送信するために使用する HTTP メソッド。 null の場合、http の既定値は POST、ftp の既定値は STOR です。
- data
- NameValueCollection
リソースに送信する NameValueCollection。
戻り値
リソースからの応答の本文を格納している Byte 配列。
例外
BaseAddress および address
を組み合わせて形成された URI が無効です。
- または -
data
は null
です。
- または -
ストリームのオープン中にエラーが発生しました。
- または -
リソースをホストしているサーバーから応答がありませんでした。
- または -
Content-type
ヘッダー値が null
ではなく、application/x-www-form-urlencoded
でもありません。
例
次のコード例では、ユーザー (名前、年齢、住所) から情報を収集し、 を使用して UploadValues値をサーバーに投稿します。 サーバーからの応答がコンソールに表示されます。
Console::Write( "\nPlease enter the URL to post data to: " );
String^ uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection^ myNameValueCollection = gcnew NameValueCollection;
Console::WriteLine( "Please enter the following parameters to be posted to the URI" );
Console::Write( "Name: " );
String^ name = Console::ReadLine();
Console::Write( "Age: " );
String^ age = Console::ReadLine();
Console::Write( "Address: " );
String^ address = Console::ReadLine();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add( "Name", name );
myNameValueCollection->Add( "Address", address );
myNameValueCollection->Add( "Age", age );
Console::WriteLine( "\nUploading to {0} ...", uriString );
// Upload the NameValueCollection.
array<Byte>^ responseArray = myWebClient->UploadValues( uriString, "POST", myNameValueCollection );
// Decode and display the response.
Console::WriteLine( "\nResponse received was :\n {0}", Encoding::ASCII->GetString( responseArray ) );
Console.Write("\nPlease enter the URL to post data to : ");
string uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();
Console.WriteLine("Please enter the following parameters to be posted to the URI");
Console.Write("Name:");
string name = Console.ReadLine();
Console.Write("Age:");
string age = Console.ReadLine();
Console.Write("Address:");
string address = Console.ReadLine();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name",name);
myNameValueCollection.Add("Address",address);
myNameValueCollection.Add("Age",age);
Console.WriteLine("\nUploading to {0} ...", uriString);
// Upload the NameValueCollection.
byte[] responseArray = myWebClient.UploadValues(uriString,"POST",myNameValueCollection);
// Decode and display the response.
Console.WriteLine("\nResponse received was :\n{0}",Encoding.ASCII.GetString(responseArray));
Console.Write(ControlChars.Cr + "Please enter the URL to post data to : ")
Dim uriString As String = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection()
Console.WriteLine("Please enter the following parameters to be posted to the Url")
Console.Write("Name:")
Dim name As String = Console.ReadLine()
Console.Write("Age:")
Dim age As String = Console.ReadLine()
Console.Write("Address:")
Dim address As String = Console.ReadLine()
' Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Address", address)
myNameValueCollection.Add("Age", age)
Console.WriteLine(ControlChars.Cr + "Uploading to {0} ...", uriString)
' Upload the NameValueCollection.
Dim responseArray As Byte() = myWebClient.UploadValues(uriString, "POST", myNameValueCollection)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :" + ControlChars.Cr + "{0}", Encoding.ASCII.GetString(responseArray))
注釈
メソッドはUploadValues、 パラメーターで指定されたメソッドを使用して リソースに をmethod
送信NameValueCollectionし、サーバーから任意の応答を返します。 このメソッドは、データのアップロード中にブロックします。 サーバーの応答を待機しながら実行を続行するには、いずれかのメソッドを UploadValuesAsync 使用します。
ヘッダーが の Content-type
場合、 null
メソッドによって UploadValues に application/x-www-form-urlencoded
設定されます。
パラメーターで method
サーバーで認識されない動詞が指定されている場合、基になるプロトコル クラスによって何が発生するかが決まります。 通常、 WebException は、エラーを示すために プロパティが Status 設定された状態でスローされます。
プロパティが空の BaseAddress 文字列 ("") address
ではなく、絶対 URI を含まない場合は、 address
と組み合わせて BaseAddress 要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが空の QueryString 文字列でない場合は、 に address
追加されます。
Note
このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「 .NET Framework でのネットワーク トレース」を参照してください。
適用対象
UploadValues(Uri, String, NameValueCollection)
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
- ソース:
- WebClient.cs
指定したメソッドを使用して、指定した URI で識別されるリソースに指定した名前/値コレクションをアップロードします。
public:
cli::array <System::Byte> ^ UploadValues(Uri ^ address, System::String ^ method, System::Collections::Specialized::NameValueCollection ^ data);
public byte[] UploadValues (Uri address, string? method, System.Collections.Specialized.NameValueCollection data);
public byte[] UploadValues (Uri address, string method, System.Collections.Specialized.NameValueCollection data);
member this.UploadValues : Uri * string * System.Collections.Specialized.NameValueCollection -> byte[]
Public Function UploadValues (address As Uri, method As String, data As NameValueCollection) As Byte()
パラメーター
- address
- Uri
コレクションを受信するリソースの URI。
- method
- String
リソースにファイルを送信するために使用する HTTP メソッド。 null の場合、http の既定値は POST、ftp の既定値は STOR です。
- data
- NameValueCollection
リソースに送信する NameValueCollection。
戻り値
リソースからの応答の本文を格納している Byte 配列。
例外
BaseAddress および address
を組み合わせて形成された URI が無効です。
- または -
data
は null
です。
- または -
ストリームのオープン中にエラーが発生しました。
- または -
リソースをホストしているサーバーから応答がありませんでした。
- または -
Content-type
ヘッダー値が null
ではなく、application/x-www-form-urlencoded
でもありません。
注釈
メソッドはUploadValues、 パラメーターで指定されたメソッドを使用して リソースに をmethod
送信NameValueCollectionし、サーバーからの応答を返します。 このメソッドは、データのアップロード中にブロックします。 サーバーの応答の待機中に実行を続行するには、いずれかのメソッドを UploadValuesAsync 使用します。
ヘッダーが の Content-type
場合、 null
メソッドはそれを UploadValues に application/x-www-form-urlencoded
設定します。
パラメーターで method
サーバーで認識されない動詞が指定されている場合、基になるプロトコル クラスによって何が発生するかが決まります。 通常、 WebException は、エラーを示すために プロパティが Status 設定された 状態でスローされます。
プロパティが BaseAddress 空の文字列 ("") address
ではなく、絶対 URI を含まない場合は、 address
と組み合わせて BaseAddress 、要求されたデータの絶対 URI を形成する相対 URI である必要があります。 プロパティが空の QueryString 文字列でない場合は、 に address
追加されます。
Note
このメンバーは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。 詳細については、「 .NET Framework でのネットワーク トレース」を参照してください。
適用対象
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示