Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WebRequest versus HTTPWebRequest
Message
From
02/01/2005 18:25:57
 
 
To
All
General information
Forum:
ASP.NET
Category:
Web control library
Title:
WebRequest versus HTTPWebRequest
Miscellaneous
Thread ID:
00973717
Message ID:
00973717
Views:
54
I have the following which retrieves the HTML from a URL. The first one cannot use a timeout. The second uses one. Can someone explain me why would someone use the first approach if it doesn't support a timeout? Are there any advantage of using the first approach?
    ' Get the HTML response from a server
    Public Shared Function GetUrl(ByVal tcUrl As String) As String
        Dim lcHTML As String
        Dim loHTTP As System.Net.WebClient = New System.Net.WebClient
        Dim loEncoding As System.Text.Encoding
        Dim loRequestedHTML() As Byte
        Try
            loRequestedHTML = loHTTP.DownloadData(tcUrl)
            lcHTML = loEncoding.Default.GetString(loRequestedHTML)
        Catch loError As Exception
            lcHTML = loError.Message
        End Try
        Return lcHTML
    End Function


    ' Get the HTML response from a server
    Public Shared Function GetUrl2(ByVal tcUrl As String, Optional ByVal tnTimeout As Integer = 5000) As String
        Dim lcHTML As String
        Dim lcUrl As New System.Uri(tcUrl)
        Dim loHTTP As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(lcUrl)
        loHTTP.Timeout = tnTimeout
        Try
            Dim loWebResponse As System.Net.WebResponse = loHTTP.GetResponse()
            Dim loStream As System.IO.Stream = loWebResponse.GetResponseStream()
            Dim loString As New System.IO.StreamReader(loStream)
            lcHTML = loString.ReadToEnd()
        Catch loError As Exception
            lcHTML = loError.Message
        End Try
        Return lcHTML
    End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Reply
Map
View

Click here to load this message in the networking platform