C# WebClient UploadData(Uri, Byte[])

Description

WebClient UploadData(Uri, Byte[]) Uploads a data buffer to a resource identified by a URI.

Syntax

WebClient.UploadData(Uri, Byte[]) has the following syntax.


public byte[] UploadData(
  Uri address,
  byte[] data
)

Parameters

WebClient.UploadData(Uri, Byte[]) has the following parameters.

  • address - The URI of the resource to receive the data.
  • data - The data buffer to send to the resource.

Returns

WebClient.UploadData(Uri, Byte[]) method returns

Example


using System;/* w  w  w.j av  a2s  .c o m*/
using System.Net;
using System.Net.Sockets;
using System.Text;

public class Example
{
    public static void Main()
    {
        string uriString = "http://java2s.com";

        WebClient myWebClient = new WebClient();

        string postData = "data";

        byte[] postArray = Encoding.ASCII.GetBytes(postData);
        Console.WriteLine("Uploading to {0} ...", uriString);
        myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
        byte[] responseArray = myWebClient.UploadData(new Uri(uriString), postArray);
        Console.WriteLine("\nResponse received was :{0}", Encoding.ASCII.GetString(responseArray));


    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient