(Swift 3,4,5...) SugarCRM Logout
Demonstrates how to logout of a session.
func chilkatTest() {
let rest = CkoRest()!
var success: Bool
success = rest.connect("your.site.domain", port: 443, tls: true, autoReconnect: true)
if success != true {
print("\(rest.lastErrorText!)")
return
}
rest.addHeader("Cache-Control", value: "no-cache")
rest.addHeader("OAuth-Token", value: "<access_token>")
let sbReq = CkoStringBuilder()!
let sbJson = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/rest/v10/oauth2/logout", requestBody: sbReq, responseBody: sbJson)
if success != true {
print("\(rest.lastErrorText!)")
return
}
if rest.responseStatusCode.intValue != 200 {
print("Received error response code: \(rest.responseStatusCode.intValue)")
print("Response body:")
print("\(sbJson.getAsString()!)")
return
}
let json = CkoJsonObject()!
json.loadSb(sbJson)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
var success: Bool
success = json.bool(of: "success")
// A sample JSON response body that is parsed by the above code:
// {
// "success": true
// }
print("Example Completed.")
}
|