HttpCurl Objective-C Reference Documentation

CkoHttpCurl

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

CkoHttpCurl *obj = [[CkoHttpCurl alloc] init];

Properties

DebugLogFilePath
@property (nonatomic, copy) NSString *DebugLogFilePath;

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
@property (nonatomic) BOOL EnableBodyVars;
Introduced in version 11.5.0

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

top
LastErrorHtml
@property (nonatomic, readonly, copy) NSString *LastErrorHtml;

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
@property (nonatomic, readonly, copy) NSString *LastErrorText;

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
@property (nonatomic, readonly, copy) NSString *LastErrorXml;

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
@property (nonatomic) BOOL LastMethodSuccess;

Indicates the success or failure of the most recent method call: YES means success, NO 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
@property (nonatomic, readonly, copy) NSString *ResponseBodyStr;
Introduced in version 11.5.0

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

top
ResponseFilePath
@property (nonatomic, copy) NSString *ResponseFilePath;
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
@property (nonatomic, readonly, copy) NSNumber *StatusCode;
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
VerboseLogging
@property (nonatomic) BOOL VerboseLogging;

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

top
Version
@property (nonatomic, readonly, copy) NSString *Version;

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

More Information and Examples
top

Methods

AddFunction
- (BOOL)AddFunction:(NSString *)funcName
    curl:(NSString *)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 YES for success, NO for failure.

top
AddOutput
- (BOOL)AddOutput:(NSString *)funcName
    jsonPath:(NSString *)jsonPath
    varName:(NSString *)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 YES for success, NO for failure.

top
AddTargetOutput
- (void)AddTargetOutput:(NSString *)jsonPath
    varName:(NSString *)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 YES for success, NO for failure.

top
ClearTargetOutput
- (void)ClearTargetOutput:(NSString *)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)ClearVar:(NSString *)varName;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
DoYourThing
- (BOOL)DoYourThing:(NSString *)targetCurl;
Introduced in version 11.5.0

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

top
DoYourThingAsync (1)
- (CkoTask *)DoYourThingAsync:(NSString *)targetCurl;
Introduced in version 11.5.0

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

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

top
ExaminePlan
- (NSString *)ExaminePlan:(NSString *)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 nil on failure

top
GetAllVars
- (void)GetAllVars:(CkoJsonObject *)json;
Introduced in version 11.5.0

Returns all defined variables in json.

top
GetResponseBd
- (BOOL)GetResponseBd:(CkoBinData *)bd;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
GetResponseJarr
- (BOOL)GetResponseJarr:(CkoJsonArray *)jarr;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
GetResponseJson
- (BOOL)GetResponseJson:(CkoJsonObject *)json;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
GetResponseSb
- (BOOL)GetResponseSb:(CkoStringBuilder *)sb;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
GetResponseXml
- (BOOL)GetResponseXml:(CkoXml *)xml;
Introduced in version 11.5.0

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

Returns YES for success, NO for failure.

top
GetVar
- (NSString *)GetVar:(NSString *)varName;
Introduced in version 11.5.0

Retrieves the current value of the variable specified by varName.

Returns nil on failure

top
SetAuth
- (BOOL)SetAuth:(CkoJsonObject *)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 YES for success, NO for failure.

top
SetVar
- (void)SetVar:(NSString *)varName
    varValue:(NSString *)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 YES for success, NO for failure.

top
ToRawRequest
- (BOOL)ToRawRequest:(NSString *)curlCommand
    sb:(CkoStringBuilder *)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 YES for success, NO for failure.

top
VarDefined
- (BOOL)VarDefined:(NSString *)varName;
Introduced in version 11.5.0

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

top

Events

To implement an event callback, your application would define and implement a class that inherits from CkoBaseProgress. Your application can implement methods to override some or all of the default/empty method implementations of the CkoBaseProgress base class.

For example:

  CkoHttpCurl *httpcurl = [[CkoHttpCurl alloc] init];

  MyHttpCurlProgress *callbackObj = [[MyHttpCurlProgress alloc] init];

  [httpcurl setEventCallbackObject:callbackObj];

MyHttpCurlProgress interface example:

#import "CkoHttpCurlProgress.h"

@interface MyHttpCurlProgress : CkoBaseProgress {

}

    - (id)init;
    - (void)dealloc;
    - (void)dispose;

    - (void)AbortCheck:(BOOL *)abort;

    - (void)PercentDone:(NSNumber *)pctDone 
        abort:(BOOL *)abort;

    - (void)ProgressInfo:(NSString *)name 
        value:(NSString *)value;

    - (void)TaskCompleted:(CkoTask *)task;

@end
AbortCheck
- (void)AbortCheck:(BOOL *)abort;

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.

More Information and Examples
top
PercentDone
- (void)PercentDone:(NSNumber *)pctDone
    abort:(BOOL *)abort;

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

To abort the operation, set the abort output argument to YES. This will cause the method to terminate and return a failure status or corresponding failure value.

More Information and Examples
top
ProgressInfo
- (void)ProgressInfo:(NSString *)name
    value:(NSString *)value;

This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

More Information and Examples
top
TaskCompleted
- (void)TaskCompleted:(CkoTask *)task;

Called from the background thread when an asynchronous task completes.

top