Advertisement
malesiak

zad2

Apr 5th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Net.Http;
  4.  
  5. namespace lab1
  6. {
  7.     class Program
  8.     {
  9.         static readonly HttpClient client = new HttpClient();
  10.  
  11.         static async Task Main()
  12.         {
  13.             Console.WriteLine("Podaj adres strony: ");
  14.             Console.Write("http://www.");
  15.             string url = "http://www." + Console.ReadLine();
  16.  
  17.             try
  18.             {
  19.                 Console.WriteLine("Trwa zliczanie znaków...");
  20.                 HttpResponseMessage response = await client.GetAsync(url);
  21.                 response.EnsureSuccessStatusCode();
  22.                 string responseBody = await response.Content.ReadAsStringAsync();
  23.  
  24.                 Console.WriteLine(responseBody.Length);
  25.             }
  26.             catch (HttpRequestException e)
  27.             {
  28.                 Console.WriteLine("\nBledny adres lub strona nie istnieje.");
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement