次の方法で共有


WebClient.UploadValues メソッド

指定した URI を持つリソースへ名前/値コレクションをアップロードします。

オーバーロードの一覧

指定した名前/値コレクションを URI で識別される指定したリソースへアップロードします。

[Visual Basic] Overloads Public Function UploadValues(String, NameValueCollection) As Byte()

[C#] public byte[] UploadValues(string, NameValueCollection);

[C++] public: unsigned char UploadValues(String*, NameValueCollection*) __gc[];

[JScript] public function UploadValues(String, NameValueCollection) : Byte[];

指定した名前/値コレクションを、指定したメソッドを使用して、指定した URI を持つ指定したリソースへアップロードします。

[Visual Basic] Overloads Public Function UploadValues(String, String, NameValueCollection) As Byte()

[C#] public byte[] UploadValues(string, string, NameValueCollection);

[C++] public: unsigned char UploadValues(String*, String*, NameValueCollection*) __gc[];

[JScript] public function UploadValues(String, String, NameValueCollection) : Byte[];

使用例

[Visual Basic, C#, C++] ユーザーから情報 (名前、年齢、および住所) を収集し、 UploadValues を使用して、それらの値をサーバーにポスト バックする例を次に示します。サーバーからの応答は、コンソールに表示されます。

[Visual Basic, C#, C++] メモ   ここでは、UploadValues のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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))

[C#] 
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));

[C++] 
Console::Write(S"\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(S"Please enter the following parameters to be posted to the URI");
Console::Write(S"Name:");
String* name = Console::ReadLine();

Console::Write(S"Age:");
String* age = Console::ReadLine();

Console::Write(S"Address:");
String* address = Console::ReadLine();

// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection->Add(S"Name", name);
myNameValueCollection->Add(S"Address", address);
myNameValueCollection->Add(S"Age", age);
Console::WriteLine(S"\nUploading to {0} ...",  uriString);

// Upload the NameValueCollection.
Byte responseArray[] = myWebClient->UploadValues(uriString, S"POST", myNameValueCollection);

// Decode and display the response.
Console::WriteLine(S"\nResponse received was :\n {0}", Encoding::ASCII->GetString(responseArray));

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

WebClient クラス | WebClient メンバ | System.Net 名前空間