![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Example: Http.DownloadAppend methodDemonstrates the DownloadAppend method.
load ./chilkat.dll set success 0 set success 0 set targetPath "c:/temp/qa_output/download.txt" set http [new_CkHttp] CkHttp_put_KeepResponseBody $http 1 # Assume the target file in the local filesystem does not yet exist. set success [CkHttp_DownloadAppend $http "https://chilkatsoft.com/testData/helloWorld.txt" $targetPath] set statusCode [CkHttp_get_LastStatus $http] if {$statusCode == 0} then { # Unable to either send the request or get the response. puts [CkHttp_lastErrorText $http] delete_CkHttp $http exit } # Should be 200. puts "Response status code: $statusCode" # Examine the contents of the file. set sb [new_CkStringBuilder] CkStringBuilder_LoadFile $sb $targetPath "utf-8" puts [CkStringBuilder_getAsString $sb] # Output: # Response status code: 200 # Hello World! # Download another text file and append to the target file. set success [CkHttp_DownloadAppend $http "https://chilkatsoft.com/testData/this_is_a_test.txt" $targetPath] set statusCode [CkHttp_get_LastStatus $http] if {$statusCode == 0} then { # Unable to either send the request or get the response. puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkStringBuilder $sb exit } # Should be 200. puts "Response status code: $statusCode" # Examine the contents of the file. CkStringBuilder_LoadFile $sb $targetPath "utf-8" puts [CkStringBuilder_getAsString $sb] # Output: # Response status code: 200 # Hello World!This is a Test. # Delete the local target file. set fac [new_CkFileAccess] CkFileAccess_FileDelete $fac $targetPath # Try to download a file that does not exist: set success [CkHttp_DownloadAppend $http "https://chilkatsoft.com/testData/does_not_exist.txt" $targetPath] set statusCode [CkHttp_get_LastStatus $http] if {$statusCode == 0} then { # Unable to either send the request or get the response. puts [CkHttp_lastErrorText $http] } else { # We got a response, and we already know it wasn't a 200 success response. # It should be a 404 not found. puts "Response status code: $statusCode" # Examine the response body. puts "Response body:" puts [CkHttp_lastResponseBody $http] } delete_CkHttp $http delete_CkStringBuilder $sb delete_CkFileAccess $fac |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.