Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(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 Extension Downloads

Chilkat Tcl Extension Downloads

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.