public static void Run() { HttpWebRequest request = GenerateHttpWebRequest(new Uri("https://www.google.com")); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { if (EX901.CategorizeResponse(response) == ResponseCategories.Success) { Console.WriteLine("Request succeeded"); } } }
public static async Task <string> GetHtmlFromUrlAsync(Uri url) { string html = string.Empty; HttpWebRequest request = EX902.GenerateHttpWebRequest(url); using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) { if (EX901.CategorizeResponse(response) == ResponseCategories.Success) { Stream stream = response.GetResponseStream(); using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { html = reader.ReadToEnd(); } } } return(html); }