Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WebRequest versus HTTPWebRequest
Message
De
02/01/2005 18:25:57
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Librairie contrôle Web
Titre:
WebRequest versus HTTPWebRequest
Divers
Thread ID:
00973717
Message ID:
00973717
Vues:
53
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
Répondre
Fil
Voir

Click here to load this message in the networking platform