Sample code for 30+ languages & platforms
Objective-C

Send a REST Request with a Text Body

See more REST Examples

Demonstrates Rest.FullRequestString, a convenience method that sends a complete request whose text body (such as JSON, XML, or plain text) is supplied directly, then reads and returns the response body as text.

Background. The full-request convenience methods perform the entire request/response exchange in a single call. FullRequestString is well suited to typical JSON or XML API calls where the body fits comfortably in a string.

Chilkat Objective-C Downloads

Objective-C
#import <CkoRest.h>
#import <NSString.h>

BOOL success = NO;

CkoRest *rest = [[CkoRest alloc] init];
BOOL bTls = YES;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"example.com" port: [NSNumber numberWithInt: 443] tls: bTls autoReconnect: bAutoReconnect];
if (success == NO) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

//  Send a complete request whose text body is supplied directly, such as JSON.  The response body is
//  read as text and returned.  The 1st argument is the HTTP verb, the 2nd is the URI path, and the
//  3rd is the request body.
[rest AddHeader: @"Content-Type" value: @"application/json"];

NSString *jsonBody = @"{ \"name\": \"example\", \"active\": true }";
NSString *responseText = [rest FullRequestString: @"POST" uriPath: @"/api/items" bodyText: jsonBody];
if (rest.LastMethodSuccess == NO) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

NSLog(@"%@",responseText);