Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to read a webpage in C#

Freaking Awesome WordPress Hosting
87 views
asked Apr 9, 2014 by avibootz
edited Mar 12, 2015 by avibootz

1 Answer

0 votes
using System;
using System.Net;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // example 1
            using (var client = new WebClient())
            {
                string htmlText = client.DownloadString("cprogramming.bootzlabs.com");

                Console.WriteLine(htmlText);
            }

            // example 2
            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("www.webshopy.com");
                WebResponse response = (HttpWebResponse)request.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader reader = new StreamReader(stream);
                string htmlText = reader.ReadToEnd();
                reader.Close();
                response.Close();

                Console.WriteLine(htmlText);
            }
            catch (WebException we)
            {
                Console.WriteLine(we.ToString());
            }
        }
    }
}




answered Apr 9, 2014 by avibootz
edited Apr 9, 2014 by avibootz

Related questions

...