C# WebClient UploadData(Uri, String, Byte[])
Description
WebClient UploadData(Uri, String, Byte[])
Uploads
a data buffer to the specified resource, using the specified method.
Syntax
WebClient.UploadData(Uri, String, Byte[])
has the following syntax.
public byte[] UploadData(
Uri address,/* w ww . j av a 2 s . co m*/
string method,
byte[] data
)
Parameters
WebClient.UploadData(Uri, String, Byte[])
has the following parameters.
address
- The URI of the resource to receive the data.method
- The HTTP method used to send the data to the resource. If null, the default is POST for http and STOR for ftp.data
- The data buffer to send to the resource.
Returns
WebClient.UploadData(Uri, String, Byte[])
method returns
Example
using System;/*from www . ja v a2 s .c o m*/
using System.Net;
using System.Net.Sockets;
using System.Text;
public class Example
{
public static void Main()
{
string uriString = "http://www.java2s.com";
WebClient myWebClient = new WebClient();
string postData = "data";
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
Console.WriteLine(myWebClient.Headers.ToString());
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
byte[] responseArray = myWebClient.UploadData(new Uri(uriString),"POST",byteArray);
Encoding.ASCII.GetString(responseArray);
}
}
The code above generates the following result.