Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27203

VS 2012 Web Request Time Out

$
0
0
I am getting a timeout error from the following code:

Code:

    Public Function DoesHTTPFileExist(WebAddress As String) As Boolean

        Dim HttpWReq As HttpWebRequest = _
        CType(WebRequest.Create(WebAddress), HttpWebRequest)

        Try
            HttpWReq.GetResponse()
        Catch x As WebException
            Dim Sx As String = x.ToString
            If Sx <> "" Then
                Return False
            End If
        End Try
        Return True
    End Function

    Public Function GetHTTPFileFromWebAddress(WebAddress As String) As String
        Dim fileinfo As String = ""
        Dim myWebReq As Net.HttpWebRequest

        myWebReq = Net.WebRequest.Create(WebAddress)
        myWebReq.UserAgent = "ie7"
        Dim resp As Net.HttpWebResponse = myWebReq.GetResponse
        Dim sr As New System.IO.StreamReader(resp.GetResponseStream)
        fileinfo = sr.ReadToEnd
        myWebReq = Nothing
        resp.Close()
        sr.Close()

        Return fileinfo

    End Function

    Public Sub CheckForNewVersionDebug()
        Dim fileinfo As String

CheckFileVersion:

        If DoesHTTPFileExist(stringOnlineVersionLocatonOfFile) Then
            fileinfo = GetHTTPFileFromWebAddress(stringOnlineVersionLocatonOfFile)
        Else
            If DoesHTTPFileExist(stringOnlineVersionLocatonOfFileSecondLink) Then
                fileinfo = GetHTTPFileFromWebAddress(stringOnlineVersionLocatonOfFileSecondLink)
            Else
                Exit Sub
            End If
        End If

        MsgBox(fileinfo)

    End Sub

If I call the CheckForNewVersionDebug function once, it works correctly, yet if I call it again, a timeout error occurs.

The following line is not executing in the GetHTTPFileFromWebAddress function:

Code:

Dim sr As New System.IO.StreamReader(resp.GetResponseStream)
Why is this happening? Is this just a server issue, or an error in my code?

Viewing all articles
Browse latest Browse all 27203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>