Sample code for 30+ languages & platforms
Objective-C

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Objective-C Downloads

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

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

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

//  To use HTTP Basic authentication:
http.Login = @"myLogin";
http.Password = @"myPassword";
http.BasicAuth = YES;

//  Run the test using this URL with the credentials above.  
//  (Works while httpbin.org keeps the test endpoint available.)
NSString *jsonResponse = [http QuickGetStr: @"https://httpbin.org/basic-auth/myLogin/myPassword"];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%@%d",@"Response status code: ",[http.LastStatus intValue]);

NSLog(@"%@",jsonResponse);

//  Output:

//  Response status code: 200
//  {
//    "authenticated": true, 
//    "user": "myLogin"
//  }