Hi all,
I was wondering is any of you knew an alternative API to InternetReadFile. I am currently using it with some success, but the only problem that I can see with it is that there is no timeout when hit a web page... so if its down the call never returns.
I know there is a InternetReadFileRev that allows you to specify the timeout, but the only problem with it is that it doesn't return the # of bytes read in. (So if I send it a 32byte buffer and it only reads in 20bytes, I want to know since the rest of the buffer will be filled with garbage).
My code looks something like this:
Can anyone suggest an alternative for me?Code:Public Function justReturnWholePageString(passedURL As String) As String Dim newlinePosition As Integer Dim hOpen As Long Dim hOpenUrl As Long Dim sUrl As String Dim LineBuffer As String Dim bDoLoop As Boolean Dim bRet As Boolean Dim sReadBuffer As String * 2048 Dim lNumberOfBytesRead As Long Dim sBuffer As String sUrl = passedURL LineBuffer = "" testLineCounter = 0 hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0) bDoLoop = True Application.ScreenUpdating = True While (bDoLoop) sReadBuffer = vbNullString bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead) LineBuffer = LineBuffer & sReadBuffer sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead) If Not CBool(lNumberOfBytesRead) Then bDoLoop = False End If Wend justReturnWholePageString = sBuffer If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl) If hOpen <> 0 Then InternetCloseHandle (hOpen) End Function
TIA!




Reply With Quote