(Objective-C) Example: Http.HttpBinary method
Demonstrates the HttpBinary method. Note: This example requires Chilkat v11.0.0 or greater.
#import <NSString.h>
#import <CkoBinData.h>
#import <CkoHttpResponse.h>
#import <CkoHttp.h>
BOOL success = NO;
NSString *localFilePath = @"C:/example/zips/data.zip";
CkoBinData *bd = [[CkoBinData alloc] init];
success = [bd LoadFile: localFilePath];
if (success == NO) {
NSLog(@"%@",bd.LastErrorText);
return;
}
NSData zipBytes;
zipBytes = [bd GetData];
NSString *url = @"https://example.com/api/v1/sites/123/deploys";
// Send a POST with a binary HTTP request body.
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoHttp *http = [[CkoHttp alloc] init];
success = [http HttpBinary: @"POST" url: url byteData: zipBytes contentType: @"application/zip" response: resp];
if (success == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%@%d",@"Response Status Code: ",[resp.StatusCode intValue]);
NSLog(@"%@",@"Response body:");
NSLog(@"%@",resp.BodyStr);
|