1 概要
WebClient webClient = new WebClient();
Stream stream = webClient.OpenRead("http://www.baidu.com");
StreamReader streamReader = new StreamReader(stream);
2 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
WebClient webClient = new WebClient();
Stream stream = webClient.OpenRead("http://www.baidu.com");
StreamReader streamReader = new StreamReader(stream);
string line;
while ((line=streamReader.ReadLine())!=null) {
Console.WriteLine(line);
}
stream.Close();
Console.ReadKey();
}
}
}
3 运行