Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collision with simultaneous hits
Message
De
19/11/2013 12:59:02
 
 
À
19/11/2013 09:10:11
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01588296
Message ID:
01588316
Vues:
35
J'aime (1)
Revised version, works well and will take care of closing everything with success or not:
    ' Get the HTML response from a server
    Public Function GetUrl() As Boolean
        Dim lcHeader As String = ""
        Dim lcUrl As System.Uri = Nothing
        Dim lcValue As String = ""
        Dim llSuccess As Boolean = False
        Dim loHttpWebRequest As System.Net.HttpWebRequest = Nothing
        Dim loObject(2) As Object
        Dim loStream As System.IO.Stream = Nothing
        Dim loStreamReader As System.IO.StreamReader = Nothing

        ' Reset the values
        cHTML = ""

        ' If we have a URL
        If cUrl.Length > 0 Then

            ' Make it into a Uri
            lcUrl = New System.Uri(cUrl)

            ' Make it into a Web request
            loHttpWebRequest = System.Net.HttpWebRequest.Create(lcUrl)

            ' If we have a timeout
            If nTimeout > 0 Then
                loHttpWebRequest.Timeout = nTimeout
            End If

            ' If we have a username
            If cUsername.Length > 0 Then
                loHttpWebRequest.Credentials = New System.Net.NetworkCredential(cUsername, cPassword)
            End If

            ' For each header
            For Each loObject In oHeader

                ' Initialization
                lcHeader = loObject(1)
                lcValue = loObject(2)

                ' Add the header
                loHttpWebRequest.Headers.Add(lcHeader, lcValue)

            Next

            ' Assign the cookie container
            loHttpWebRequest.CookieContainer = oCookieContainer

            Using loHttpWebResponse As System.Net.HttpWebResponse = loHttpWebRequest.GetResponse()

                Try
                    loStream = loHttpWebResponse.GetResponseStream()
                    loStreamReader = New System.IO.StreamReader(loStream)
                    cHTML = loStreamReader.ReadToEnd()
                    llSuccess = True
                Catch loError As Exception
                    cMessage = loError.Message
                End Try

            End Using

        Else
            cMessage = cURLCannotBeEmpty
        End If

        ' Reset the values
        cPassword = ""
        cUrl = ""
        cUsername = ""
        nTimeout = 0
        oHeader.Clear()

        Return llSuccess
    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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform