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


(1) The close statements are not where they should be.
(2) Don't you have to close loStream ?


Why not 3 nested 'using' ?

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

Click here to load this message in the networking platform