(C++) SugarCRM Logout
Demonstrates how to logout of a session.
#include <CkRest.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
CkRest rest;
bool success;
success = rest.Connect("your.site.domain",443,true,true);
if (success != true) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
rest.AddHeader("Cache-Control","no-cache");
rest.AddHeader("OAuth-Token","<access_token>");
CkStringBuilder sbReq;
CkStringBuilder sbJson;
success = rest.FullRequestSb("POST","/rest/v10/oauth2/logout",sbReq,sbJson);
if (success != true) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
if (rest.get_ResponseStatusCode() != 200) {
std::cout << "Received error response code: " << rest.get_ResponseStatusCode() << "\r\n";
std::cout << "Response body:" << "\r\n";
std::cout << sbJson.getAsString() << "\r\n";
return;
}
CkJsonObject json;
json.LoadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
bool success;
success = json.BoolOf("success");
// A sample JSON response body that is parsed by the above code:
// {
// "success": true
// }
std::cout << "Example Completed." << "\r\n";
}
|