Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcLocalFilePath
LOCAL lnStatusCode
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
loHttp.KeepResponseBody = 1
* Download a .zip
lcLocalFilePath = "/temp/hamlet.zip"
lnSuccess = loHttp.Download("https://www.chilkatsoft.com/hamlet.zip",lcLocalFilePath)
lnStatusCode = loHttp.LastStatus
IF (lnSuccess = 0) THEN
IF (lnStatusCode = 0) THEN
* Unable to either send the request or get the response.
? loHttp.LastErrorText
ELSE
* We got a response, but the status code was not in the 200s
? "Response status code: " + STR(lnStatusCode)
* Examine the response body.
? "Response body:"
? loHttp.LastResponseBody
ENDIF
? "Download failed."
ELSE
? "Download success, response status = " + STR(lnStatusCode)
ENDIF
* Download an XML file:
lcLocalFilePath = "/temp/hamlet.xml"
lnSuccess = loHttp.Download("https://www.chilkatsoft.com/hamlet.xml",lcLocalFilePath)
* ...
* Check for errors in the same way as shown above..
* ...
? "OK!"
RELEASE loHttp