The ReadURL Function

Public Function ReadURL(ByVal sUrl As String) As Boolean

Dim sReadBuffer         As String * 2048 ' bytes to read from call to InternetReadFile
Dim lNumberOfBytesRead  As Long         ' bytes read from call to InternetReadFile
Dim lTotalBytesRead     As Long         ' total bytes read
Dim bDoLoop             As Boolean      ' return value from InternetReadFile
Dim bReadInternetFile   As Boolean

' Call Internet Server API to open the URL
hUrlFile = InternetOpenUrl(hInternetSession, sUrl, vbNullString, 0, INTERNET_FLAG_EXISTING_CONNECT, 0)

' If successful open the URL
If CBool(hUrlFile) Then
    sContents = scBlankStr
    bDoLoop = True
    While bDoLoop
        ' Keep reading from the URL till EOF
        sReadBuffer = scBlankStr
        ' Call Internet Server API to read from URL
        bDoLoop = InternetReadFile(hUrlFile, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
        lTotalBytesRead = lTotalBytesRead + lNumberOfBytesRead
        If CBool(lNumberOfBytesRead) Then
                ' Keep appending to sContents variable
                sContents = sContents & Left$(sReadBuffer, lNumberOfBytesRead)
        Else
            bDoLoop = False
            bReadInternetFile = True
        End If
    Wend
    ' Call Internet Server API to close the session
    InternetCloseHandle (hUrlFile)
    ReadUrl = True
Else
    ReadUrl = False
End If
Exit Function
End Function