Exemplo n.º 1
0
        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");
                }
            }
        }
Exemplo n.º 2
0
        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);
        }