WebClient.UploadData メソッド
指定した URI を持つリソースへデータ バッファをアップロードします。
オーバーロードの一覧
URI で識別されたリソースへデータ バッファをアップロードします。
[Visual Basic] Overloads Public Function UploadData(String, Byte()) As Byte()
[C++] public: unsigned char UploadData(String*, unsigned char __gc[]) __gc[];
[JScript] public function UploadData(String, Byte[]) : Byte[];
このメンバは、.NET Framework インフラストラクチャのサポートを目的としています。独自に作成したコード内で直接使用することはできません。
[Visual Basic] Overloads Public Function UploadData(String, String, Byte()) As Byte()
[C++] public: unsigned char UploadData(String*, String*, unsigned char __gc[]) __gc[];
[JScript] public function UploadData(String, String, Byte[]) : Byte[];
使用例
[Visual Basic, C#, C++] The following example converts a string entered from the console into a byte array and posts the array to the specified server using UploadData. Any response from the server is displayed to the console.
[Visual Basic, C#, C++] メモ ここでは、UploadData のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for example, https://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))
[C#]
string uriString;
Console.Write("\nPlease enter the URI to post data to {for example, https://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));
[C++]
String* uriString;
Console::Write(S"\nPlease enter the URI to post data to {for example, https://www.contoso.com} : ");
uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient* myWebClient = new WebClient();
Console::WriteLine(S"\nPlease enter the data to be posted to the URI {0}:", uriString);
String* postData = Console::ReadLine();
myWebClient->Headers->Add(S"Content-Type", S"application/x-www-form-urlencoded");
// Apply ASCII Encoding to obtain the String* as a Byte array.
Byte byteArray[] = Encoding::ASCII->GetBytes(postData);
Console::WriteLine(S"Uploading to {0} ...", uriString);
// Upload the input String* using the HTTP 1.0 POST method.
Byte responseArray[] = myWebClient->UploadData(uriString, S"POST", byteArray);
// Decode and display the response.
Console::WriteLine(S"\nResponse received was {0}",
Encoding::ASCII->GetString(responseArray));
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。