指定した名前/値コレクションを、指定したメソッドを使用して、指定した URI を持つ指定したリソースへアップロードします。
Overloads Public Function UploadValues( _
ByVal address As String, _ ByVal method As String, _ ByVal data As NameValueCollection _) As Byte()
[C#]
public byte[] UploadValues(stringaddress,stringmethod,NameValueCollectiondata);
[C++]
public: unsigned char UploadValues(String* address,String* method,NameValueCollection* data) __gc[];
[JScript]
public function UploadValues(
address : String,method : String,data : NameValueCollection) : Byte[];
パラメータ
- address
コレクションを受信するリソースの URI。 - method
リソースにファイルを送信するために使用するメソッド動詞。 - data
リソースに送信する NameValueCollection 。
戻り値
リソースからの応答の本体を保持しているバイトの配列。
例外
例外の種類 | 条件 |
---|---|
WebException | BaseAddress および address を組み合わせて形成された URI が無効です。
または data が null 参照 (Visual Basic では Nothing) です。 または ストリームのオープン中にエラーが発生しました。 または リソースをホストしているサーバーから応答がありませんでした。 または Content-type ヘッダーが "application/x-www-form-urlencoded" ではありません。 |
解説
UploadValues メソッドは、 method パラメータで指定したメソッド動詞を使用してリソースに NameValueCollection を送信し、サーバーからの応答を返します。
Content-type ヘッダーが null 参照 (Visual Basic では Nothing) の場合、 UploadValues メソッドは、Content-type ヘッダーを "Content-type: application/x-www-form-urlencoded" に設定します。
method パラメータによってサーバーが認識できない動詞が指定された場合は、発生する内容は、基になるプロトコル クラスによって決定されます。通常は、エラーを示す Status プロパティ セットと共に WebException がスローされます。
BaseAddress プロパティが空でない場合、 address は、相対 URI である必要があります。この相対 URI は、 BaseAddress と結合されて、要求されたデータの絶対 URI を形成します。 QueryString プロパティが空でない場合は、 address に追加されます。
使用例
[Visual Basic, C#, C++] ユーザーから情報 (名前、年齢、および住所) を収集し、 UploadValues を使用して、それらの値をサーバーにポスト バックする例を次に示します。サーバーからの応答は、コンソールに表示されます。
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
参照
WebClient クラス | WebClient メンバ | System.Net 名前空間 | WebClient.UploadValues オーバーロードの一覧