wxBasic Forum

wxBasic => Beispiele | Examples => Thema gestartet von: GM_FrEaK in 19.03.2017, 23:27:35 NACHMITTAGS

Titel: Objektorientierte Programmierung Beispiel
Beitrag von: GM_FrEaK in 19.03.2017, 23:27:35 NACHMITTAGS
Hier eine Funktionierende Downloader Klasse  8)

Class Downloader
Function Download(Adress, File, Overwrite = TRUE, Port = 80)
If !Overwrite And FileExists(File) Then
Return FALSE
End If

Dim http = New wxHTTP()
Dim uri = New wxURI(Adress)
http.SetTimeout(10)

While !http.Connect(uri.GetServer(), Port)
wxSleep(1)
Wend

Dim stream = http.GetInputStream(uri.GetPath())
If (http.GetError() = wxPROTO_NOERR) Then
Dim FileHandle = FOpen(File, "w")
While !stream.Eof()
Dim chunk = stream.Read(1024)
FPuts(FileHandle, chunk)
Wend
FClose(FileHandle)
Else
Return FALSE
End If
End Function
End Class