Objective-C
Objective-C
Add a Query Parameter from a StringBuilder
See more REST Examples
Demonstrates Rest.AddQueryParamSb, which adds or replaces a query parameter whose value is read from a StringBuilder. The 1st argument is the name and the 2nd is the StringBuilder.
Background. This variant is convenient when the parameter value has already been assembled in a StringBuilder, avoiding an extra conversion to a plain string.
Chilkat Objective-C Downloads
#import <CkoRest.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
BOOL success = NO;
CkoRest *rest = [[CkoRest alloc] init];
// Connect to the REST server. The 3rd argument enables TLS (use true for HTTPS on port 443),
// and the 4th enables automatic reconnection if the connection is dropped between requests.
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;
}
// The parameter value can also be supplied from a StringBuilder. The 1st argument is the name and
// the 2nd is the StringBuilder holding the value.
CkoStringBuilder *sbValue = [[CkoStringBuilder alloc] init];
[sbValue Append: @"chilkat rest"];
[rest AddQueryParamSb: @"q" value: sbValue];
NSString *responseText = [rest FullRequestNoBody: @"GET" uriPath: @"/api/search"];
if (rest.LastMethodSuccess == NO) {
NSLog(@"%@",rest.LastErrorText);
return;
}
NSLog(@"%@",responseText);