Hire my services

If you would like to hire my services, you can now do so by visiting the following link:

Website Design Darlington

Article Statistics

ArticlesLatest Entry
2121-May-2008

Code Bank Statistics

CategoryTipsLatest Entry
Applications420-Feb-2008
Cache118-Apr-2007
Controls926-Jul-2007
CSS107-Sep-2007
Database428-Aug-2007
Dates128-Aug-2007
Email105-Mar-2007
Files123-Apr-2007
HTML101-Mar-2007
Images226-Mar-2007
Pages115-Oct-2007
Sessions122-Nov-2007
SQL Server1518-Mar-2008
Strings309-May-2007
Skip Navigation LinksHome > Articles > Retrieve data from a web page

Retrieve data from a web page

Summary: An example of how we can make a request to a web page and retrieve the resulting HTMLSocialize it

There are a few situations where it would be useful to be able to retrieve the HTML from a web page via code. Fortunately, this is made relatively easy by the HttpWebRequest and httpWebResponse classes.

Firstly, we need to decide which type of form the web page is using. The two different methods are GET and POST and for this article, I'm going to assume you have a basic understanding of these methods and I'll simply show you an example of how to implement either method rather than go into the differences between them. For both methods we'll need a simple page to actually display the results so let's start by making a page with a TextBox on it:


Now, we need to write the code based on whichever method we have decided to use.

Using the GET method

This is the shorter of the two methods as since we don't have to post any data we can simply set the URL and add any querystring values to that URL. We can then simply make a request using this URL and read the response given back to us:


Using the POST method

This method is slightly longer than the GET method due to the fact that we actually have to specify the data that is going to be sent to the page. We also have to set the actual type and length of this content before posting it so the page in question knows what it will be receiving:


Both of these simple examples demonstrate an easy method of reading the results of a request to a web page. You can obviously parse the results if necessary and only display certain information from the web page but this article will at least get you up to that point.

Reader Comments

1. DUB 03/04/2007 12:42:22

2. Mark Smith 04/04/2007 00:29:02

3. TCDooM 14/04/2007 01:31:05

4. wooncherk 14/04/2007 03:06:05

5. Mohammad Azam 14/04/2007 09:18:23

6. atarikg 18/04/2007 13:54:43

7. kalai 14/08/2007 20:32:37

8. Vinay 16/08/2007 08:31:25

9. Craig 26/10/2007 16:20:15

10. manish kapde 08/11/2007 09:28:21

11. Manish Garg 27/12/2007 01:50:56

12. Kumar 10/01/2008 05:20:48

13. Leonardo 13/03/2008 10:21:52

14. jay praaksh tiwari 15/03/2008 07:55:16

15. Susan Kefgen 08/05/2008 14:50:17

16. pinkpanter 11/06/2008 06:15:17

17. Ramanathan 06/01/2009 12:36:30

Add your comments

Please keep your comments relevant to this page. Any inappropriate or purely promotional comments may be removed. Email addresses are never displayed but are required so you can confirm your comments.

Your Name:
 
Your Email:
 
Add your comments: