WebClient.UploadData Method
.NET Framework 1.1
Uploads a data buffer to a resource with the specified URI.
Overload List
Uploads a data buffer to a resource identified by a URI.
[Visual Basic] Overloads Public Function UploadData(String, Byte()) As Byte()
[C#] public byte[] UploadData(string, byte[]);
[C++] public: unsigned char UploadData(String*, unsigned char __gc[]) __gc[];
[JScript] public function UploadData(String, Byte[]) : Byte[];
This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
[Visual Basic] Overloads Public Function UploadData(String, String, Byte()) As Byte()
[C#] public byte[] UploadData(string, string, byte[]);
[C++] public: unsigned char UploadData(String*, String*, unsigned char __gc[]) __gc[];
[JScript] public function UploadData(String, String, Byte[]) : Byte[];
Example
[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++] Note This example shows how to use one of the overloaded versions of UploadData. For other examples that might be available, see the individual overload topics.
[Visual Basic] 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)) [C#] 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)); [C++] String* uriString; Console::Write(S"\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(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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.