Sample code for 30+ languages & platforms
Objective-C

HTTP POST with Binary Data in Request Body

See more HTTP Examples

Do an HTTPS POST with a binary request body.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoFileAccess.h>
#import <CkoHttpResponse.h>

BOOL success = NO;

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

CkoHttp *http = [[CkoHttp alloc] init];

CkoFileAccess *fac = [[CkoFileAccess alloc] init];

NSData reqBody;
reqBody = [fac ReadEntireFile: @"qa_data/pdf/helloWorld.pdf"];

CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpBinary: @"POST" url: @"https://example.com/something" byteData: reqBody contentType: @"application/pdf" response: resp];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

int responseStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Status code: ",responseStatusCode);

// For example, if the response is XML, JSON, HTML, etc.
NSLog(@"%@",@"response body:");
NSLog(@"%@",resp.BodyStr);