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);
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.
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
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.
See Also:C Example using Callback Functions
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.
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.
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_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.
EnableBodyVars
void CkHttpCurl_putEnableBodyVars(HCkHttpCurl cHandle, BOOL newVal);
Enables variable substitution in the body of the request. The default value is TRUE.
LastErrorHtml
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.
topLastErrorText
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.
LastErrorXml
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.
topLastMethodSuccess
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.
ResponseBodyStr
const char *CkHttpCurl_responseBodyStr(HCkHttpCurl cHandle);
Returns the HTTP response body from the last call to DoYourThing .
ResponseFilePath
void CkHttpCurl_putResponseFilePath(HCkHttpCurl cHandle, const char *newVal);
const char *CkHttpCurl_responseFilePath(HCkHttpCurl cHandle);
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 .
StatusCode
Returns the HTTP status code from the last call to DoYourThing. A value of 0 indicates no response header was received.
Utf8
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.
VerboseLogging
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.
Version
const char *CkHttpCurl_version(HCkHttpCurl cHandle);
Methods
AddFunction
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.
topAddOutput
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.
topAddTargetOutput
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.
topClearTargetOutput
Clears (undefines) the target output for the specified varName. If varName equals "*", then all target outputs are cleared.
ClearVar
Undefines the variable with the specified name. If varName equals "*", then all variables are cleared.
Returns TRUE for success, FALSE for failure.
topDoYourThing
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:
- If
ResponseFilePathis non-empty, the response body was streamed to the specified file path. - If
ResponseFilePathis empty, the response body can be retrieved viaResponseBodyStr,GetResponseSb, orGetResponseBd. Binary responses should only be retrieved viaResponseBodyBd.
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.
topDoYourThingAsync (1)
Creates an asynchronous task to call the DoYourThing method with the arguments provided.
Returns NULL on failure
ExaminePlan
const char *CkHttpCurl_examinePlan(HCkHttpCurl cHandle, const char *curl);
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.
topGetAllVars
Returns all defined variables in json.
topGetResponseBd
Writes to bd the HTTP response body from the last call to DoYourThing.
Returns TRUE for success, FALSE for failure.
topGetResponseJarr
Writes to jarr the HTTP response body from the last call to DoYourThing.
Returns TRUE for success, FALSE for failure.
topGetResponseJson
Writes to json the HTTP response body from the last call to DoYourThing.
Returns TRUE for success, FALSE for failure.
topGetResponseSb
Writes to sb the HTTP response body from the last call to DoYourThing.
Returns TRUE for success, FALSE for failure.
topGetResponseXml
Writes to xml the HTTP response body from the last call to DoYourThing.
Returns TRUE for success, FALSE for failure.
topGetVar
const char *CkHttpCurl_getVar(HCkHttpCurl cHandle, const char *varName);
Retrieves the current value of the variable specified by varName.
Returns TRUE for success, FALSE for failure.
topSetAuth
Sets authorization information that is applied to all calls to DoYourThing . See the examples below for details.
Returns TRUE for success, FALSE for failure.
topSetVar
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.
ToRawRequest
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.
topVarDefined
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.