Sample code for 30+ languages & platforms
Objective-C

MedTunnel: Logout

See more MedTunnel Examples

Close the session for the logged in User.

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.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];

// Implements the following CURL command:

// curl -X GET -k 
//         -H "Authorization:PutAuthorizationTokenHere" 
//         https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/Logout

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

[http SetRequestHeader: @"Authorization" value: @"PutAuthorizationTokenHere"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: @"https://server.medtunnel.com/MedTunnelSvc/api/Authenticate/Logout" sbContent: sbResponseBody];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",http.LastHeader);
    NSLog(@"%@",@"Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "ReturnCode": 1,
//   "ReturnCodeText": "Success",
//   "Data": "1"
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

int ReturnCode = [[jResp IntOf: @"ReturnCode"] intValue];
NSString *ReturnCodeText = [jResp StringOf: @"ReturnCodeText"];
NSString *Data = [jResp StringOf: @"Data"];