Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting the best approach to get content from a server
Message
From
01/10/2006 19:14:38
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Getting the best approach to get content from a server
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01158464
Message ID:
01158464
Views:
69
I have these three methods that allow me to get the content from a server:
        ' Get the HTML response from a server
        ' expC1 Url
        Public Function GetXML(ByVal tcUrl As String) As String
            Dim loReq As System.Net.WebRequest
            Dim lcHtml As String
            loReq = System.Net.WebRequest.Create(tcUrl)
            Dim loResponse As System.Net.WebResponse = loReq.GetResponse()
            Dim loStream As Stream = loResponse.GetResponseStream()
            Dim loStreamReader As StreamReader = New StreamReader(loStream)
            lcHtml = loStreamReader.ReadToEnd()
            Return lcHtml
        End Function

        ' Get the HTML response from a server
        ' expC1 Url
        Public 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 = New System.Text.ASCIIEncoding
            Dim loRequestedHTML() As Byte
            Try
                loRequestedHTML = loHTTP.DownloadData(tcUrl)
                lcHTML = loEncoding.GetString(loRequestedHTML)
            Catch loError As Exception
                lcHTML = loError.Message
            End Try
            Return lcHTML
        End Function

        ' Get the HTML response from a server
        ' expC1 Url
        ' expN1 Timeout
        Public Function GetUrlTimeout(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
They use a different approach in each. I was wondering if there would be one to consider mostly than the others. One is using System.Net.WebRequest, the other one System.Net.WebClient and the last one System.Net.HttpWebRequest. Any feedback?
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