Tcl
Tcl
QuickGetBd Example
The QuickGetBd method is called to send a GET request to download a binary target, such as PDF, zip, image file, etc. into a Chilkat BinData object.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
CkHttp_put_KeepResponseBody $http 1
set bd [new_CkBinData]
# Download the contents of a PDF file into the bd object.
set success [CkHttp_QuickGetBd $http "https://www.chilkatsoft.com/hello.pdf" $bd]
if {$success == 0} then {
# This will happen if the response status code was 400 or greater,
# or if the request could not be sent, or if no response was received.
#
# In other words, success will only be 1 if bd contains the desired content at the URL (not an error response).
set statusCode [CkHttp_get_LastStatus $http]
puts "Response status: $statusCode"
if {$statusCode == 0} then {
# There was an error in communications.
puts [CkHttp_lastErrorText $http]
} else {
# We received a response status code indicating failure.
# Examine the response body.
puts [CkHttp_lastResponseBody $http]
}
delete_CkHttp $http
delete_CkBinData $bd
exit
}
# Load the downloaded PDF into a Chilkat PDF object.
set pdf [new_CkPdf]
set success [CkPdf_LoadBd $pdf $bd]
if {$success == 0} then {
puts [CkPdf_lastErrorText $pdf]
delete_CkHttp $http
delete_CkBinData $bd
delete_CkPdf $pdf
exit
}
# ...
puts "Success."
delete_CkHttp $http
delete_CkBinData $bd
delete_CkPdf $pdf