C# HttpClient Get获取网页内容

2021-04-07 06:25

阅读:562

标签:ade   pid   close   IV   TE   网页   client   linq   AC   

 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 }

 

C# HttpClient Get获取网页内容

标签:ade   pid   close   IV   TE   网页   client   linq   AC   

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


评论


亲,登录后才可以留言!