I've been using this library function to download pages from the internet, and it's worked great for months.
Now it doesn't work anymore. The problem is that the server seems to have a delay in it. When browsing manually, much of the page gets drawn, then there's a second or two delay, then the rest of the page gets drawn.Code:Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer Public Function DownloadURL(pstrURL As String) As String Const INTERNET_OPEN_TYPE_PRECONFIG = 0 Const INTERNET_FLAG_RELOAD = &H80000000 Dim strBuffer As String * 4096 Dim strReturn As String Dim lngLen As Long Dim lngSession As Long Dim lngFile As Long Dim blnSuccess As Boolean lngSession = InternetOpen("GSInternet", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) lngFile = InternetOpenUrl(lngSession, pstrURL, vbNullString, 0, INTERNET_FLAG_RELOAD, 0) If lngFile Then Do blnSuccess = InternetReadFile(lngFile, strBuffer, Len(strBuffer), lngLen) If lngLen Then strReturn = strReturn & Left$(strBuffer, lngLen) Loop While blnSuccess And lngLen > 0 InternetCloseHandle (lngFile) DownloadURL = strReturn End If End Function
That second or two delay seems to be killing the above utility function. What happens now is the function only returns the half of the page that gets sent before the second or two delay.
Does anyone know how or why this would happen, and any way to fix it?




Reply With Quote