Back to Collection Items
#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
bool success;
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "password": "{{password}}",
// "usernameOrEmailAddress": "{{usernameOrEmailAddress}}",
// "tenancyName": "{{tenant}}"
// }
CkJsonObject json;
json.UpdateString("password","{{password}}");
json.UpdateString("usernameOrEmailAddress","{{usernameOrEmailAddress}}");
json.UpdateString("tenancyName","{{tenant}}");
// Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>");
CkHttpResponse *resp = http.PostJson3("https://domain.com/api/Account/Authenticate","application/json",json);
if (http.get_LastMethodSuccess() == false) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
CkStringBuilder sbResponseBody;
resp->GetBodySb(sbResponseBody);
CkJsonObject jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
std::cout << "Response Body:" << "\r\n";
std::cout << jResp.emit() << "\r\n";
int respStatusCode = resp->get_StatusCode();
std::cout << "Response Status Code = " << respStatusCode << "\r\n";
if (respStatusCode >= 400) {
std::cout << "Response Header:" << "\r\n";
std::cout << resp->header() << "\r\n";
std::cout << "Failed." << "\r\n";
delete resp;
return;
}
delete resp;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "result": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjVENzg4QTgyMEE4QzAzMkJBNzg1Mjk4QjNBMTlEMkNGMEQyODI2ODYiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJYWGlLZ2dxTUF5dW5oU21MT2huU3p3MG9Kb1kifQ.eyJuYmYiOjE2MTc5NzQ1NjYsImV4cCI6MTYxNzk3ODQ2NiwiaXNzIjoiaHR0cHM6Ly9wdGFvcmNoMjAxMC1pcy5henVyZXdlYnNpdGVzLm5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ereBA9E_PgiMTv7D3NbKcyqLUNmTScVfWBM92qMw9UzKh1_fl5qjN3DtfdRWek8AJowxkgDskNScemdkemXAS2cGSgFc7JxEsxmZWa8CSxuSuVw9XSsFc37GaZo3t2XusJR8P55frEzcycfnxfDOJfp8iFmaMY9slUiAXX1Y4lo6_LJBBld1_y_AxRzHBskvsNc5WZwFCfrMM27NjFATfrODToECkWq-S3s-rI6h-mjQZECta4PG9cDYK5cyPB6yYp9VY2FqMg4znUIphyQIVRgHUsC2cGSo-UGZdCrgX5J4za5b3ze9OoAY",
// "targetUrl": null,
// "success": true,
// "error": null,
// "unAuthorizedRequest": false,
// "__abp": true
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
const char *result = jResp.stringOf("result");
const char *targetUrl = jResp.stringOf("targetUrl");
bool success = jResp.BoolOf("success");
const char *error = jResp.stringOf("error");
bool unAuthorizedRequest = jResp.BoolOf("unAuthorizedRequest");
bool v__abp = jResp.BoolOf("__abp");
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"password": "{{password}}",
"usernameOrEmailAddress": "{{usernameOrEmailAddress}}",
"tenancyName": "{{tenant}}"
}'
https://domain.com/api/Account/Authenticate
Postman Collection Item JSON
{
"name": "Authenticate (OnPrem)",
"event": [
{
"listen": "test",
"script": {
"exec": [
"//test status code\r",
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"password\": \"{{password}}\",\r\n \"usernameOrEmailAddress\": \"{{usernameOrEmailAddress}}\",\r\n \"tenancyName\": \"{{tenant}}\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{OnPremUrl}}/api/Account/Authenticate",
"host": [
"{{OnPremUrl}}"
],
"path": [
"api",
"Account",
"Authenticate"
]
}
},
"response": [
{
"name": "Authenticate (OnPrem)",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"password\": \"{{password}}\",\r\n \"usernameOrEmailAddress\": \"{{usernameOrEmailAddress}}\",\r\n \"tenancyName\": \"{{tenant}}\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{OnPremUrl}}/api/Account/Authenticate",
"host": [
"{{OnPremUrl}}"
],
"path": [
"api",
"Account",
"Authenticate"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Cache-Control",
"value": "no-cache, no-store, must-revalidate"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Expires",
"value": "-1"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Request-Context",
"value": "appId=cid-v1:947add8d-3c5d-4dda-a0ab-9f714fdafac3"
},
{
"key": "X-Robots-Tag",
"value": "noindex, nofollow"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "X-XSS-Protection",
"value": "1"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "Deny"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: https://*.blob.core.windows.net https://*.amazonaws.com blob:;font-src 'self' data:;connect-src 'self' wss: https://sentry.io https://studio-feedback.azure-api.net https://*.service.signalr.net https://*.blob.core.windows.net https://*.amazonaws.com dc.services.visualstudio.com;worker-src 'self' blob:"
},
{
"key": "X-Correlation-ID",
"value": "b707aed0-bdf0-4a36-a74f-e87176e3d256"
},
{
"key": "api-supported-versions",
"value": "11.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rW_L3LwCeRDlSf1NIpIykyCjTdprPp7QgbOmB5FRf7H1778ZY3pkPY4C_EH60lTqraNKe66E09vTpRPlASQoWrbUprNSxkVd7KLTQ16QUthelVsml_D39uSCBfhiUJR0N4Bpr9GF5IVsGOuRgwQtXiw4Gi-7hlWBX5qhnj3GO29uVO5oiSJJtKlMTqWO8iIZloURFdVxYUpXuywH6nEmeUFdIvOsUcFKjPOkpUW2SdIPqWjy7yTplAXoXny1yKBfPbEkwtivvOrzRz6fz6rPQO8qNTKcAf28oeO2iLYWRN7u4AIKLgPdpkbXjwgrrVXgY3Duvw6yjBsC2Yt9Iu6DJMXq2ereBA9E_PgiMTv7D3NbKcyqLUNmTScVfWBM92qMw9UzKh1_fl5qjN3DtfdRWek8AJowxkgDskNScemdkemXAS2cGSgFc7JxEsxmZWa8CSxuSuVw9XSsFc37GaZo3t2XusJR8P55frEzcycfnxfDOJfp8iFmaMY9slUiAXX1Y4lo6_LJBBld1_y_AxRzHBskvsNc5WZwFCfrMM27NjFATfrODToECkWq-S3s-rI6h-mjQZECta4PG9cDYK5cyPB6yYp9VY2FqMg4znUIphyQIVRgHUsC2cGSo-UGZdCrgX5J4za5b3ze9OoAY\",\n \"targetUrl\": null,\n \"success\": true,\n \"error\": null,\n \"unAuthorizedRequest\": false,\n \"__abp\": true\n}"
}
]
}