Download the resource as a Byte array from the URI specified in CSharp

Description

The following code shows how to download the resource as a Byte array from the URI specified.

Example


using System;/*from  ww  w . j  av  a2  s.c  o  m*/
using System.Net;
using System.Net.Sockets;
using System.Text;

public class Example
{
    public static void Main()
    {
        WebClient myWebClient = new WebClient();
        byte[] myDataBuffer = myWebClient.DownloadData(new Uri("http://www.java2s.com"));
        string download = Encoding.ASCII.GetString(myDataBuffer);
        Console.WriteLine(download);


    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client