Tcl
Tcl
Explaining the Rest ClearResponseBodyStream Method
See more Azure Cloud Storage Examples
The ClearResponseBodyStream method would be needed if your applicaiton called SetResponseBodyStream to send the response to a stream for one request, but then wants to subsequently do something else. The application must call ClearResponseBodyStream to no longer send responses to the stream.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rest [new_CkRest]
# Connect to the web server
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "www.chilkatsoft.com" $port $bTls $bAutoReconnect]
if {$success != 1} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
# Setup a file stream for the download
set fileStream [new_CkStream]
CkStream_put_SinkFile $fileStream "qa_output/starfish.jpg"
# Indicate that the call to FullRequestNoBody should send the response body
# to fileStream if the response status code is 200.
# If a non-success response status code is received, then nothing
# is streamed to the output file and the error response is returned by FullRequestNoBody.
set expectedStatus 200
CkRest_SetResponseBodyStream $rest $expectedStatus 1 $fileStream
set responseStr [CkRest_fullRequestNoBody $rest "GET" "/images/starfish.jpg"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
# Examine the request/response to see what happened.
puts "response status code = [CkRest_get_ResponseStatusCode $rest]"
puts "response status text = [CkRest_responseStatusText $rest]"
puts "response header: [CkRest_responseHeader $rest]"
puts "response body (if any): $responseStr"
puts "---"
puts "LastRequestStartLine: [CkRest_lastRequestStartLine $rest]"
puts "LastRequestHeader: [CkRest_lastRequestHeader $rest]"
delete_CkRest $rest
delete_CkStream $fileStream
exit
}
puts "downloaded starfish.jpg"
# Clear the response body stream previously set in the call to SetResponseBodyStream.
CkRest_ClearResponseBodyStream $rest
# Download something else, but this time send the response body to bd.
set bd [new_CkBinData]
set success [CkRest_FullRequestNoBodyBd $rest "GET" "/images/penguins.jpg" $bd]
if {$success == 0} then {
# Examine the request/response to see what happened.
puts "response status code = [CkRest_get_ResponseStatusCode $rest]"
puts "response status text = [CkRest_responseStatusText $rest]"
puts "response header: [CkRest_responseHeader $rest]"
puts "response body (if any): [CkBinData_getString $bd utf-8]"
puts "---"
puts "LastRequestStartLine: [CkRest_lastRequestStartLine $rest]"
puts "LastRequestHeader: [CkRest_lastRequestHeader $rest]"
delete_CkRest $rest
delete_CkStream $fileStream
delete_CkBinData $bd
exit
}
# Save the contents of bd to a file.
set success [CkBinData_WriteFile $bd "qa_output/penguins.jpg"]
puts "Success: $success"
delete_CkRest $rest
delete_CkStream $fileStream
delete_CkBinData $bd