C# HttpClient Get获取网页内容

时间:2018-05-31 12:13:09   收藏:0   阅读:481
 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 }

 

原文:https://www.cnblogs.com/ybst/p/9115934.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!