HttpCurl C 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.

Create/Dispose

HCkHttpCurl instance = CkHttpCurl_Create();
// ...
CkHttpCurl_Dispose(instance);
HCkHttpCurl CkHttpCurl_Create(void);

Creates an instance of the HCkHttpCurl object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkHttpCurl_Dispose(HCkHttpCurl handle);

Objects created by calling CkHttpCurl_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkHttpCurl_Dispose.

Callback Functions

void CkHttpCurl_setAbortCheck(HCkHttpCurl cHandle, BOOL (*fnAbortCheck)(void));

Provides the opportunity for a method call to be aborted. If TRUE is returned, the operation in progress is aborted. Return FALSE to allow the current method call to continue. This callback function is called periodically based on the value of the HeartbeatMs property. (If HeartbeatMs is 0, then no callbacks are made.) As an example, to make 5 AbortCheck callbacks per second, set the HeartbeatMs property equal to 200.

void CkHttpCurl_setPercentDone(HCkHttpCurl cHandle, BOOL (*fnPercentDone)(int pctDone));

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This callback is only called when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For methods that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

This callback counts as an AbortCheck callback, and takes the place of the AbortCheck event when it fires.

The return value indicates whether the method call should be aborted, or whether it should proceed. Return TRUE to abort, and FALSE to proceed.

void CkHttpCurl_setProgressInfo(HCkHttpCurl cHandle, void (*fnProgressInfo)(const char *name, const char *value));

This is a general callback that provides name/value information about what is happening at certain points during a method call. To see the information provided in ProgressInfo callbacks, if any, write code to handle this event and log the name/value pairs. Most are self-explanatory.

void CkHttpCurl_setTaskCompleted(HCkHttpCurl cHandle, void (*fnTaskCompleted)(HCkTask hTask));

Called in the background thread when an asynchronous task completes. (Note: When an async method is running, all callbacks are in the background thread.)

Properties

DebugLogFilePath
void CkHttpCurl_getDebugLogFilePath(HCkHttpCurl cHandle, HCkString retval);
void CkHttpCurl_putDebugLogFilePath(HCkHttpCurl cHandle, const char *newVal);
const char *CkHttpCurl_debugLogFilePath(HCkHttpCurl cHandle);

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
BOOL CkHttpCurl_getEnableBodyVars(HCkHttpCurl cHandle);
void CkHttpCurl_putEnableBodyVars(HCkHttpCurl cHandle, BOOL newVal);
Introduced in version 11.5.0

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

top
LastErrorHtml
void CkHttpCurl_getLastErrorHtml(HCkHttpCurl cHandle, HCkString retval);
const char *CkHttpCurl_lastErrorHtml(HCkHttpCurl cHandle);

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
void CkHttpCurl_getLastErrorText(HCkHttpCurl cHandle, HCkString retval);
const char *CkHttpCurl_lastErrorText(HCkHttpCurl cHandle);

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
void CkHttpCurl_getLastErrorXml(HCkHttpCurl cHandle, HCkString retval);
const char *CkHttpCurl_lastErrorXml(HCkHttpCurl cHandle);

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
BOOL CkHttpCurl_getLastMethodSuccess(HCkHttpCurl cHandle);
void CkHttpCurl_putLastMethodSuccess(HCkHttpCurl cHandle, BOOL newVal);

Indicates the success or failure of the most recent method call: TRUE means success, FALSE 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
void CkHttpCurl_getResponseBodyStr(HCkHttpCurl cHandle, HCkString retval);
const char *CkHttpCurl_responseBodyStr(HCkHttpCurl cHandle);
Introduced in version 11.5.0

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

top
ResponseFilePath
void CkHttpCurl_getResponseFilePath(HCkHttpCurl cHandle, HCkString retval);
void CkHttpCurl_putResponseFilePath(HCkHttpCurl cHandle, const char *newVal);
const char *CkHttpCurl_responseFilePath(HCkHttpCurl cHandle);
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
int CkHttpCurl_getStatusCode(HCkHttpCurl cHandle);
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
BOOL CkHttpCurl_getUtf8(HCkHttpCurl cHandle);
void CkHttpCurl_putUtf8(HCkHttpCurl cHandle, BOOL newVal);

When set to TRUE, all const char * arguments and return values are interpreted as UTF-8 strings. When set to FALSE, they are interpreted as ANSI strings.

In Chilkat v11.0.0 and later, the default value is TRUE. Before v11.0.0, it was FALSE.

top
VerboseLogging
BOOL CkHttpCurl_getVerboseLogging(HCkHttpCurl cHandle);
void CkHttpCurl_putVerboseLogging(HCkHttpCurl cHandle, BOOL newVal);

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

top
Version
void CkHttpCurl_getVersion(HCkHttpCurl cHandle, HCkString retval);
const char *CkHttpCurl_version(HCkHttpCurl cHandle);

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

More Information and Examples
top

Methods

AddFunction
BOOL CkHttpCurl_AddFunction(HCkHttpCurl cHandle, const char *funcName, const char *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 TRUE for success, FALSE for failure.

top
AddOutput
BOOL CkHttpCurl_AddOutput(HCkHttpCurl cHandle, const char *funcName, const char *jsonPath, const char *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 TRUE for success, FALSE for failure.

top
AddTargetOutput
void CkHttpCurl_AddTargetOutput(HCkHttpCurl cHandle, const char *jsonPath, const char *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 TRUE for success, FALSE for failure.

top
ClearTargetOutput
void CkHttpCurl_ClearTargetOutput(HCkHttpCurl cHandle, const char *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
void CkHttpCurl_ClearVar(HCkHttpCurl cHandle, const char *varName);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
DoYourThing
BOOL CkHttpCurl_DoYourThing(HCkHttpCurl cHandle, const char *targetCurl);
Introduced in version 11.5.0

Runs a the curl command specified in targetCurl. Returns success (TRUE) 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 TRUE for success, FALSE for failure.

top
DoYourThingAsync (1)
HCkTask CkHttpCurl_DoYourThingAsync(HCkHttpCurl cHandle, const char *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
BOOL CkHttpCurl_ExaminePlan(HCkHttpCurl cHandle, const char *curl, HCkString outStr);
const char *CkHttpCurl_examinePlan(HCkHttpCurl cHandle, const char *curl);
Introduced in version 11.5.0

Used for debugging. Returns a string that provides information about 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.

Returns TRUE for success, FALSE for failure.

top
GetAllVars
void CkHttpCurl_GetAllVars(HCkHttpCurl cHandle, HCkJsonObject json);
Introduced in version 11.5.0

Returns all defined variables in json.

top
GetResponseBd
BOOL CkHttpCurl_GetResponseBd(HCkHttpCurl cHandle, HCkBinData bd);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
GetResponseJarr
BOOL CkHttpCurl_GetResponseJarr(HCkHttpCurl cHandle, HCkJsonArray jarr);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
GetResponseJson
BOOL CkHttpCurl_GetResponseJson(HCkHttpCurl cHandle, HCkJsonObject json);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
GetResponseSb
BOOL CkHttpCurl_GetResponseSb(HCkHttpCurl cHandle, HCkStringBuilder sb);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
GetResponseXml
BOOL CkHttpCurl_GetResponseXml(HCkHttpCurl cHandle, HCkXml xml);
Introduced in version 11.5.0

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

Returns TRUE for success, FALSE for failure.

top
GetVar
BOOL CkHttpCurl_GetVar(HCkHttpCurl cHandle, const char *varName, HCkString outStr);
const char *CkHttpCurl_getVar(HCkHttpCurl cHandle, const char *varName);
Introduced in version 11.5.0

Retrieves the current value of the variable specified by varName.

Returns TRUE for success, FALSE for failure.

top
SetAuth
BOOL CkHttpCurl_SetAuth(HCkHttpCurl cHandle, HCkJsonObject 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 TRUE for success, FALSE for failure.

top
SetVar
void CkHttpCurl_SetVar(HCkHttpCurl cHandle, const char *varName, const char *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 TRUE for success, FALSE for failure.

top
ToRawRequest
BOOL CkHttpCurl_ToRawRequest(HCkHttpCurl cHandle, const char *curlCommand, HCkStringBuilder 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 TRUE for success, FALSE for failure.

top
VarDefined
BOOL CkHttpCurl_VarDefined(HCkHttpCurl cHandle, const char *varName);
Introduced in version 11.5.0

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

top