Objective-C
Objective-C
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat Objective-C Downloads
#import <CkoRest.h>
#import <CkoStringBuilder.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;
}
// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder. This avoids extra string conversions for large bodies.
CkoStringBuilder *sbRequest = [[CkoStringBuilder alloc] init];
[sbRequest Append: @"{ \"query\": \"chilkat\" }"];
[rest AddHeader: @"Content-Type" value: @"application/json"];
CkoStringBuilder *sbResponse = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/api/search" requestBody: sbRequest responseBody: sbResponse];
if (success == NO) {
NSLog(@"%@",rest.LastErrorText);
return;
}
NSString *responseText = [sbResponse GetAsString];
if (sbResponse.LastMethodSuccess == NO) {
NSLog(@"%@",sbResponse.LastErrorText);
return;
}
NSLog(@"%@",responseText);