(Objective-C) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body. Note: This example requires Chilkat v11.0.0 or greater.
#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);
|