![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]() |

|
| Programming tutorials All Knowledge Info and links to posted here |
![]() |
|
Get Web Page Contents in Code with C#
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) | |
|
Administrator
Posts: 18,715
Join Date: Jan 2006
Rep Power: 10
IM:
|
The .NET framework provides a rich set of methods to access data stored on the web. First you will have to include the right namespaces: Quote:
We'll use a StreamReader object to read the response into a string variable. Here's the actual code: Code:
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL); myRequest.Method = "GET"; WebResponse myResponse = myRequest.GetResponse(); StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); string result = sr.ReadToEnd(); sr.Close(); myResponse.Close(); In this code sample, the URL variable should contain the URL that you want to get, and the result variable will contain the contents of the web page. You may want to add some error handling as well for a real application. |
|
|
|
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PodLift - Browse the contents of any iPod | Spirit-X | Application Downloads | 0 | 30-Dec-2007 07:26 AM |
| Safari shows blank page when trying to view PHP site. Content appears when page is re | Anilrgowda | Mac - Operating Systems and Applications Error | 1 | 18-Oct-2007 12:38 AM |
| Master Page and content page Title problem VS2005 | Sangeetha | Knowledge Base | 1 | 27-Feb-2007 08:53 PM |
| PHP: Get the contents of a web page, RSS feed, or XML file into a string variable | Anilrgowda | Programming tutorials | 0 | 20-Dec-2006 04:09 AM |
| Printing the contents of a PHP Array | Anilrgowda | Programming tutorials | 0 | 20-Dec-2006 04:09 AM |