Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Explaining the Rest ClearResponseBodyStream MethodSee more Azure Cloud Storage ExamplesThe 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.
load ./chilkat.dll # 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.