Sample code for 30+ languages & platforms
Objective-C

Example: Http.DownloadSb method

See more HTTP Examples

Demonstrates the DownloadSb method.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

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

CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
success = [http DownloadSb: @"https://chilkatsoft.com/testData/helloWorld.txt" charset: @"utf-8" sb: sb];

int statusCode = [http.LastStatus intValue];
if (success == NO) {
    if (statusCode == 0) {
        //  Unable to either send the request or get the response.
        NSLog(@"%@",http.LastErrorText);
    }
    else {
        //  We got a response, but the status code was not in the 200s
        NSLog(@"%@%d",@"Response status code: ",statusCode);
        //  Examine the response body.
        NSLog(@"%@",@"Response body:");
        NSLog(@"%@",http.LastResponseBody);
    }

    NSLog(@"%@",@"Download failed.");

}
else {
    NSLog(@"%@%d",@"Download success, response status = ",statusCode);
    NSLog(@"%@",[sb GetAsString]);
}