Sample code for 30+ languages & platforms
Objective-C

Example: Http.QuickGet method

Demonstrates the QuickGet method.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoZip.h>
#import <CkoZipEntry.h>
#import <NSString.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
http.KeepResponseBody = YES;

//  This URL is valid and can be tested...
NSData zipBytes;
zipBytes = [http QuickGet: @"https://chilkatdownload.com/example_data/hamlet.zip"];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

if ([http.LastStatus intValue] != 200) {
    NSLog(@"%@%d",@"Response status code: ",[http.LastStatus intValue]);
    NSLog(@"%@",http.LastResponseBody);
    return;
}

CkoZip *zip = [[CkoZip alloc] init];

//  Open the zip from the bytes contained in bd.
success = [zip OpenFromMemory: zipBytes];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

//  Get the entry for the file we want..
CkoZipEntry *entry = [[CkoZipEntry alloc] init];
success = [zip EntryOf: @"hamlet.xml" entry: entry];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

//  Convert all line endings to CRLF (if needed)
int lineEndingBehavior = 2;
NSString *xmlStr = [entry UnzipToString: [NSNumber numberWithInt: lineEndingBehavior] srcCharset: @"utf-8"];
if (entry.LastMethodSuccess == NO) {
    NSLog(@"%@",entry.LastErrorText);
    return;
}

//  The XML in this case is about 274K, so let's just examine the last 20 lines...
CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
[sb Append: xmlStr];

NSLog(@"%@",[sb LastNLines: [NSNumber numberWithInt: 20] bCrlf: YES]);