C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Retrieve web pages programmatically using WebResponse object


Posted Date: 15 Feb 2007    Resource Type: Code Snippets    Category: Web Access

Posted By: Tony John       Member Level: Gold
Rating:     Points: 10



This code snippet shows how to programmatically retrieve the content of any web site using the WebResponse object part of the System.Net namespace.


Public Shared Function GetHttpPage(ByVal pageUrl As String) As String
Dim response As System.Net.WebResponse = Nothing

Try
'' Setup our Web request
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(pageUrl)
request.Timeout = 10000

'' Retrieve data from request
response = request.GetResponse()

Dim streamReceive As System.IO.Stream = response.GetResponseStream()
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim streamRead As System.IO.StreamReader = New System.IO.StreamReader(streamReceive, encoding)

'' return the retrieved HTML
Return streamRead.ReadToEnd()
Finally
''Check if exists, then close the response.
If Not response Is Nothing Then
response.Close()
End If
End Try
End Function




Responses

Author: Ryan Jayford    08 Aug 2007Member Level: Bronze   Points : 0
Invalid URI: The format of the URI could not be determined error
pageUrl = "WordNoticeTemplate.aspx?cid=23"

What seems to be the problem.
Thanks,
Rj


Feedbacks      
Popular Tags   What are tags ?   Search 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.
Previous Resource: How to access Cookies from web pages
Return to Discussion Resource Index
Post New Resource
Category: Web Access


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use