C# HttpClient Get获取网页内容

using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Net;
 using System.Text;
 using System.Threading.Tasks;
 
 namespace WinSpider
 {
     public static class Extentions
     {
         public static string ReadString(this Stream stream, bool autoClose=true)
         {
             using (StreamReader reader = new StreamReader(stream))
             {
                 string str = reader.ReadToEnd();
                 if(autoClose)
                     stream.Close();
                 return str;
             }
         }
 
         public static string GetString(this WebClient web, string url)
         { 
             return web.OpenRead(url).ReadString();
         }
     }
 }

相关推荐