C# HttpClient Get获取网页内容

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Net;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 
 9 namespace WinSpider
10 {
11     public static class Extentions
12     {
13         public static string ReadString(this Stream stream, bool autoClose=true)
14         {
15             using (StreamReader reader = new StreamReader(stream))
16             {
17                 string str = reader.ReadToEnd();
18                 if(autoClose)
19                     stream.Close();
20                 return str;
21             }
22         }
23 
24         public static string GetString(this WebClient web, string url)
25         { 
26             return web.OpenRead(url).ReadString();
27         }
28     }
29 }