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 !




Download the HTML at a given URL


Posted Date: 11 Mar 2004    Resource Type: Articles    Category: .NET Framework
Author: Satheesh SugumaranMember Level: Gold    
Rating: Points: 7



The following function GetHtmlPageSource download the HTML source code at the specified URL. We can optionally specify the username/password credentials, in case the page uses Basic Authentication.This function returns a null string if any error occurs


Function GetHtmlPageSource(ByVal url As String, Optional ByVal username As _
String = Nothing, Optional ByVal password As String = Nothing) As String
Dim st As System.IO.Stream
Dim sr As System.IO.StreamReader

Try
' make a Web request
Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)
' if the username/password are specified, use these credentials
If Not username Is Nothing AndAlso Not password Is Nothing Then
req.Credentials = New System.Net.NetworkCredential(username, _
password)
End If
' get the response and read from the result stream
Dim resp As System.Net.WebResponse = req.GetResponse
st = resp.GetResponseStream
sr = New System.IO.StreamReader(st)
' read all the text in it
Return sr.ReadToEnd
Catch ex As Exception
Return ""
Finally
' always close readers and streams
sr.Close()
st.Close()
End Try
End Function




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

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.
Next Resource: Validate an IP address
Previous Resource: Reflection
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use