Open a readable stream for the data downloaded from a resource with the URI specified as a Uri in CSharp

Description

The following code shows how to open a readable stream for the data downloaded from a resource with the URI specified as a Uri.

Example


using System;/*from  www. j  av a  2  s. c o  m*/
using System.Net;
using System.Net.Sockets;
using System.IO;

public class Example
{
    public static void Main()
    {
        WebClient myWebClient = new WebClient();
        Stream myStream = myWebClient.OpenRead(new Uri("http://java2s.com"));

        StreamReader sr = new StreamReader(myStream);
        Console.WriteLine(sr.ReadToEnd());
        myStream.Close();

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client