同步请求资源
请求msdn上的一个页面计算页面大小
static void Main(string[] args)
{ string url = "https://docs.microsoft.com/zh-cn/dotnet/core/api/system"; try
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse(); using (var reader = new StreamReader(response.GetResponseStream()))
{ string text = reader.ReadToEnd();
Console.WriteLine(FormatBytes(text.Length));
}
} catch (WebException e)
{
} catch (IOException e)
{
} catch (NotSupportedException e)
{
}
}static string FormatBytes(long bytes)
{ string[] magnitudes = new string[] { "GB", "MB", "KB", "Bytes" }; long max = (long)Math.Pow(1024, magnitudes.Length); var t1 = magnitudes.FirstOrDefault(magnitude => bytes > (max /= 10


