(Objective-C) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body.
#import <CkoHttp.h>
#import <CkoFileAccess.h>
#import <NSString.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;
CkoFileAccess *fac = [[CkoFileAccess alloc] init];
NSData reqBody;
reqBody = [fac ReadEntireFile: @"qa_data/pdf/helloWorld.pdf"];
NSString *responseStr = [http PostBinary: @"https://example.com/something" byteData: reqBody contentType: @"application/pdf" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
int responseStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Status code: ",responseStatusCode);
// For example, if the response is XML, JSON, HTML, etc.
NSLog(@"%@",@"response body:");
NSLog(@"%@",responseStr);
|