C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Retrieving HTML content from a given URL by making a web request


Posted Date: 04 Nov 2004    Resource Type: Articles    Category: .NET Framework
Author: Hubli SunilMember Level: Diamond    
Rating: 1 out of 5Points: 7



Introduction
The main classes used for this purpose are HttpWebRequest and HttpWebResponse. HttpWebRequest is used to make the http request for a given url. We have to set the "Method" property as “GET” for this purpose. GetResponse() method of HttpWebRequest class gives the html response of the request.

Remaining work of reading response stream and writing html content in to a text file is as follows.


Dim objRequest As HttpWebRequest = WebRequest.Create("http://www.google.com")
Dim result As String
objRequest.Method = "GET"
Dim objResponse As HttpWebResponse = objRequest.GetResponse()
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()
Dim oFile As File
Dim oWrite As StreamWriter
oWrite = oFile.CreateText("C:/Windows/temp/google.txt")
oWrite.Write(result)
oWrite.Close()


Summary
This method is very useful in developing bots (robots). For example, if we want to retrieve a specific portion of data from a web page. But we have to do extra coding for that after getting the response stream.




Responses

Author: DotNET-Helper    04 Nov 2004Member Level: Gold   Points : 0
Please check the link and submit ur option

http://www.dotnetspider.com/technology/qa/ViewQuestion.aspx?QuestionId=2649


Author: Taru Jagannath    04 Nov 2004Member Level: Silver   Points : 0
It's really int. Artical.
Sunil, I want to save image(jpg/gif) using this code... How can i.

I already have StramReader as u create (result) how can i display image in browser and save in Harddrive.

_ Thanks


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Duplicating Object with Clone
Previous Resource: Exceptions in the .net framework
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use