Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collision with simultaneous hits
Message
De
18/11/2013 22:13:50
 
 
À
18/11/2013 21:36:46
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:
01588297
Vues:
37
There was a bad object being used. This had to be HttpWebResponse instead of WebResponse. I also added the close of the objects.

This now works. Here is the GetUrl() method:
    ' 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 loHttpWebResponse As System.Net.HttpWebResponse = 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

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

            loHttpWebResponse.Close()
            loStreamReader.Close()
        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