DataFlex
DataFlex
HTTP Download any Type of File (binary or text)
See more HTTP Examples
TheDownload method can download any file type, whether binary (e.g., .zip, .pdf) or text (.xml, .txt), without distinction. It streams the file byte-for-byte from the web server exactly as received. This same process applies to web pages: providing a URL typically viewed in a browser downloads the server's delivered HTML to a file.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
String sLocalFilePath
Integer iStatusCode
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComKeepResponseBody Of hoHttp To True
// Download a .zip
Move "/temp/hamlet.zip" To sLocalFilePath
Get ComDownload Of hoHttp "https://www.chilkatsoft.com/hamlet.zip" sLocalFilePath To iSuccess
Get ComLastStatus Of hoHttp To iStatusCode
If (iSuccess = False) Begin
If (iStatusCode = 0) Begin
// Unable to either send the request or get the response.
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
End
Else Begin
// We got a response, but the status code was not in the 200s
Showln "Response status code: " iStatusCode
// Examine the response body.
Showln "Response body:"
Get ComLastResponseBody Of hoHttp To sTemp1
Showln sTemp1
End
Showln "Download failed."
End
Else Begin
Showln "Download success, response status = " iStatusCode
End
// Download an XML file:
Move "/temp/hamlet.xml" To sLocalFilePath
Get ComDownload Of hoHttp "https://www.chilkatsoft.com/hamlet.xml" sLocalFilePath To iSuccess
// ...
// Check for errors in the same way as shown above..
// ...
Showln "OK!"
End_Procedure