
Internet via WINAPI: PLEASE HELP!
Hi everybody!
I am working on a program that downloads different sites automatically.
I have three questions concening WINAPIs possibilities to help me do that.
1. I have the problem that my downlaod function seems to cache the contents
I am downloading. How can I avoid that using only WINAPI?
2. When I download certain sites that want to save cookies, I see the IE
popup asking wheter to save it or not. I do not want this to happen. Do you
know how to disable all cookies in WINAPI? I know how to change IE security
configuration, so please: WINAPI solutions.
3. The most serious problem I am faced with is, that some of the sites I
want to download use to time out once in a while. This situation freezes my
code. How can I tell my program to start an error handling routine after 30
seconds of inactivity?
Here is what my code looks like: (I apologize for using VB but it is the
only language I know.)
Public Sub pgFileDownloader(ByVal vUrl As String, ByVal vSavePath As String)
Dim vInternetSession As Long
Dim vFile As Long
Dim vPf As Integer
Dim vReadBuffer() As Byte
Dim vNumberOfBytesRead As Long
Dim vDoLoop As Boolean
Dim vDelFile As Boolean
vInternetSession = InternetOpen("pgFileDownloader",
INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
vFile = InternetOpenUrl(vInternetSession, vUrl, "", 0, 0, 0)
vPf = FreeFile
Open vSavePath For Binary As vPf
vDoLoop = True
While vDoLoop
Erase vReadBuffer()
ReDim vReadBuffer(64)
vDoLoop = InternetReadFile(vFile, vReadBuffer(0), 65,
vNumberOfBytesRead)
If CBool(vNumberOfBytesRead) Then
ReDim Preserve vReadBuffer(vNumberOfBytesRead - 1)
Put #vPf, LOF(vPf) + 1, vReadBuffer
Else
vDoLoop = False
End If
Wend
If LOF(vPf) = 0 Then
vDelFile = True
Else
vDelFile = False
End If
Close #vPf
InternetCloseHandle vFile
InternetCloseHandle vInternetSession
If vDelFile Then
Kill vSavePath
End If
End Sub
I appreciate your help,
Sebastian R.