HttpCurl Tcl Reference Documentation

HttpCurl

Current Version: 11.4.0

A class for running curl commands within your application. Mirrors the curl command syntax. It is not derived from curl/libcurl, and does not wrap libcurl.

Object Creation

# 'this' is not a keyword in Tcl. It can freely be used as a variable name.
set this [new CkHttpCurl]

Properties

DebugLogFilePath
string
# ckStr is a CkString
CkHttpCurl_get_DebugLogFilePath $this $ckStr
set strVal [CkHttpCurl_get_debugLogFilePath $this]
CkHttpCurl_put_DebugLogFilePath $this $strVal

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
EnableBodyVars
boolean 1/0
set boolVal [CkHttpCurl_get_EnableBodyVars $this]
CkHttpCurl_put_EnableBodyVars $this $boolVal
Introduced in version 11.5.0

Enables variable substitution in the body of the request. The default value is 1.

top
FailedCurl
string
# ckStr is a CkString
CkHttpCurl_get_FailedCurl $this $ckStr
set strVal [CkHttpCurl_get_failedCurl $this]
Introduced in version 11.5.0

Set to the specific curl command in the execution plan that failed.

top
FailReason
integer
set intVal [CkHttpCurl_get_FailReason $this]
Introduced in version 11.5.0

Set to an integer value indicating the reason for failure for the methods DoYourThing and ExaminePlan

Possible values are:

  1. No error - the method succeeded or hasn't yet been called.
  2. curl command syntax error.
  3. HTTP response status code indidcates an authentication (401) or authorization (403) error.
  4. HTTP response status code indicates an error, but not an authentication or authorization error.
  5. HTTP communications failure.
  6. Impossible to derive an execution plan from defined outputs and inputs.
  7. A step in the execution plan did not resolve any dependency variables.
  8. Failed to get curl data from a local file source (see the note below).
  9. If we are within a Chilkat.Js context and don't have permission to read the local filesystem.
  10. Chilkat has not been successfully unlocked by previously and successfully calling UnlockBundle.

Note: curl can read data from a local file and send it in a request (usually POST/PUT) using special syntax:

  • -d @file.txt → reads the file and sends it as request body (form-style encoding).
  • --data-binary @file.bin → sends raw file contents exactly as-is.
  • -F "file=@file.txt" → uploads the file as multipart/form-data.

The @ tells curl to load the data from a local file instead of using a literal string.

top
LastErrorHtml
string
# ckStr is a CkString
CkHttpCurl_get_LastErrorHtml $this $ckStr
set strVal [CkHttpCurl_get_lastErrorHtml $this]

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
string
# ckStr is a CkString
CkHttpCurl_get_LastErrorText $this $ckStr
set strVal [CkHttpCurl_get_lastErrorText $this]

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
string
# ckStr is a CkString
CkHttpCurl_get_LastErrorXml $this $ckStr
set strVal [CkHttpCurl_get_lastErrorXml $this]

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
boolean 1/0
set boolVal [CkHttpCurl_get_LastMethodSuccess $this]
CkHttpCurl_put_LastMethodSuccess $this $boolVal

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
ResponseBodyStr
string
# ckStr is a CkString
CkHttpCurl_get_ResponseBodyStr $this $ckStr
set strVal [CkHttpCurl_get_responseBodyStr $this]
Introduced in version 11.5.0

Returns the HTTP response body from the last call to DoYourThing .

top
ResponseFilePath
string
# ckStr is a CkString
CkHttpCurl_get_ResponseFilePath $this $ckStr
set strVal [CkHttpCurl_get_responseFilePath $this]
CkHttpCurl_put_ResponseFilePath $this $strVal
Introduced in version 11.5.0

Set this property to the path of a file to stream the response body to a file. If the response is streamed to a file, it will not be available in ResponseBodyStr , GetResponseSb , or GetResponseBd .

top
StatusCode
integer
set intVal [CkHttpCurl_get_StatusCode $this]
Introduced in version 11.5.0

Returns the HTTP status code from the last call to DoYourThing. A value of 0 indicates no response header was received.

top
Utf8
boolean 1/0
set boolVal [CkHttpCurl_get_Utf8 $this]
CkHttpCurl_put_Utf8 $this $boolVal

When set to 1, all string arguments and return values are interpreted as UTF-8 strings. When set to 0, they are interpreted as ANSI strings.

In Chilkat v11.0.0 and later, the default value is 1. Before v11.0.0, it was 0.

top
VerboseLogging
boolean 1/0
set boolVal [CkHttpCurl_get_VerboseLogging $this]
CkHttpCurl_put_VerboseLogging $this $boolVal

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
string
# ckStr is a CkString
CkHttpCurl_get_Version $this $ckStr
set strVal [CkHttpCurl_get_version $this]

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AddFunction
# funcName is a string
# curl is a string
set status [CkHttpCurl_AddFunction $this $funcName $curl]
Introduced in version 11.5.0

Adds a named curl function that can be used in dependency resolution. Inputs required by the curl function are indicated by the variable names enclosed in {{ and }}. Outputs are defined in one or more calls to AddOutput .

Returns 1 for success, 0 for failure.

More Information and Examples
top
AddOutput
# funcName is a string
# jsonPath is a string
# varName is a string
set status [CkHttpCurl_AddOutput $this $funcName $jsonPath $varName]
Introduced in version 11.5.0

Adds a defined output for a dependency resolution curl function previously defined by calling AddFunction. The jsonPath is the JSON path in the JSON response body where the varName's value is located.

Returns 1 for success, 0 for failure.

More Information and Examples
top
AddTargetOutput
# jsonPath is a string
# varName is a string
set status [CkHttpCurl_AddTargetOutput $this $jsonPath $varName]
Introduced in version 11.5.0

Adds an automatically mapped variable for the target curl command. When a JSON response is received from a curl request, the value at the JSON path specified by jsonPath is extracted (if present) and assigned to the variable named by varName.

This is useful in common workflows where one request returns an identifier (such as an `id`) that must be reused in a subsequent curl request.

Returns 1 for success, 0 for failure.

More Information and Examples
top
ClearTargetOutput
# varName is a string
CkHttpCurl_ClearTargetOutput $this $varName
Introduced in version 11.5.0

Clears (undefines) the target output for the specified varName. If varName equals "*", then all target outputs are cleared.

top
ClearVar
# varName is a string
set status [CkHttpCurl_ClearVar $this $varName]
Introduced in version 11.5.0

Undefines the variable with the specified name. If varName equals "*", then all variables are cleared.

Returns 1 for success, 0 for failure.

top
DoYourThing
# targetCurl is a string
set status [CkHttpCurl_DoYourThing $this $targetCurl]
Introduced in version 11.5.0

Runs a the curl command specified in targetCurl. Returns success (1) if a response was received, in which case the response status code will be available in StatusCode and the content of the response body will be available in one of two places:

Assuming the HTTP response is JSON, the target outputs (variables) specified by prior calls to AddTargetOutput will be populated by applying each variable's JSON path to the response JSON.

Returns 1 for success, 0 for failure.

top
DoYourThingAsync (1)
# returns a CkTask
# targetCurl is a string
set ret_task [CkHttpCurl_DoYourThingAsync $this $targetCurl]
Introduced in version 11.5.0

Creates an asynchronous task to call the DoYourThing method with the arguments provided.

Returns NULL on failure

top
ExaminePlan
# curl is a string
# json is a CkJsonObject
set status [CkHttpCurl_ExaminePlan $this $curl $json]
Introduced in version 11.5.0

Used for debugging. Returns in json the plan of execution that would occur for the curl based on the variables that are either unknown or already known. The plan of execution is what would occur if DoYourThing was called with the current state of knowledge.

If no execution plan is possible with the current known inputs and outputs, then json provides information about what is missing and the method returns 0.

Returns 1 for success, 0 for failure.

top
GetAllVars
# json is a CkJsonObject
CkHttpCurl_GetAllVars $this $json
Introduced in version 11.5.0

Returns all defined variables in json.

More Information and Examples
top
GetResponseBd
# bd is a CkBinData
set status [CkHttpCurl_GetResponseBd $this $bd]
Introduced in version 11.5.0

Writes to bd the HTTP response body from the last call to DoYourThing.

Returns 1 for success, 0 for failure.

top
GetResponseJarr
# jarr is a CkJsonArray
set status [CkHttpCurl_GetResponseJarr $this $jarr]
Introduced in version 11.5.0

Writes to jarr the HTTP response body from the last call to DoYourThing.

Returns 1 for success, 0 for failure.

top
GetResponseJson
# json is a CkJsonObject
set status [CkHttpCurl_GetResponseJson $this $json]
Introduced in version 11.5.0

Writes to json the HTTP response body from the last call to DoYourThing.

Returns 1 for success, 0 for failure.

top
GetResponseSb
# sb is a CkStringBuilder
set status [CkHttpCurl_GetResponseSb $this $sb]
Introduced in version 11.5.0

Writes to sb the HTTP response body from the last call to DoYourThing.

Returns 1 for success, 0 for failure.

top
GetResponseXml
# xml is a CkXml
set status [CkHttpCurl_GetResponseXml $this $xml]
Introduced in version 11.5.0

Writes to xml the HTTP response body from the last call to DoYourThing.

Returns 1 for success, 0 for failure.

top
GetVar
# varName is a string
# outStr is a CkString (output)
set status [CkHttpCurl_GetVar $this $varName $outStr]
set retStr [CkHttpCurl_getVar $this $varName]
Introduced in version 11.5.0

Retrieves the current value of the variable specified by varName.

Returns 1 for success, 0 for failure.

top
SetAuth
# json is a CkJsonObject
set status [CkHttpCurl_SetAuth $this $json]
Introduced in version 11.5.0

Sets authorization information that is applied to all calls to DoYourThing . See the examples below for details.

Returns 1 for success, 0 for failure.

top
SetVar
# varName is a string
# varValue is a string
set status [CkHttpCurl_SetVar $this $varName $varValue]
Introduced in version 11.5.0

Sets the value of a variable to be replaced in curl commands. Variable names are enclosed in {{ and }} and can occur in the path, query params, or the body of the request.

Returns 1 for success, 0 for failure.

top
ToRawRequest
# curlCommand is a string
# sb is a CkStringBuilder
set status [CkHttpCurl_ToRawRequest $this $curlCommand $sb]
Introduced in version 11.5.0

Used for debugging purposes. This method behaves the same as DoYourThing , but only converts the curlCommand to an HTTP request message in sb containing the full structure:

  • start line
  • headers
  • optional body or multipart body

It does not actually send the HTTP request.

Returns 1 for success, 0 for failure.

top
VarDefined
# varName is a string
set retBool [CkHttpCurl_VarDefined $this $varName]
Introduced in version 11.5.0

Returns 1 if the varName is defined, otherwise returns 0. Setting varName to "!" checks whether all target output variables have been defined. It returns 1 if every target output is set, and 0 if any are missing.

top