Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *result;
const char *targetUrl;
BOOL success;
const char *error;
BOOL unAuthorizedRequest;
BOOL v__abp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// 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}}"
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"password","{{password}}");
CkJsonObject_UpdateString(json,"usernameOrEmailAddress","{{usernameOrEmailAddress}}");
CkJsonObject_UpdateString(json,"tenancyName","{{tenant}}");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
resp = CkHttp_PostJson3(http,"https://domain.com/api/Account/Authenticate","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "result": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjVENzg4QTgyMEE4QzAzMkJBNzg1Mjk4QjNBMTlEMkNGMEQyODI2ODYiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJYWGlLZ2dxTUF5dW5oU21MT2huU3p3MG9Kb1kifQ.eyJuYmYiOjE2MTc5NzQ1NjYsImV4cCI6MTYxNzk3ODQ2NiwiaXNzIjoiaHR0cHM6Ly9wdGFvcmNoMjAxMC1pcy5henVyZXdlYnNpdGVzLm5ldC9pZGVudGl0eSIsImF1ZCI6Ik9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiLCJjbGllbnRfaWQiOiI0ZDdmMmJmMi05MDkzLTQ5NTktOWQ1Mi1iNGE2NjBmMTQ4NWYiLCJzdWIiOiJkNGFiODFlNi00NjU5LTRjMjUtOGFjNy0wYTQ4MGFhZTE3ZjAiLCJhdXRoX3RpbWUiOjE2MTc5NzQ4NjYsImlkcCI6ImxvY2FsIiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiJTWFoyTUFJV0wzSUxBNUtLWVZBM1pWWFdURERKRVU2WCIsInBydF9pZCI6IjNkZDg0NGQwLWZjY2YtMGUyZC04ZTE4LWMyZTNiMzExYTBhZiIsImhvc3QiOiJGYWxzZSIsImZpcnN0X25hbWUiOiJDb2RlIFNjaWVuY2UiLCJsYXN0X25hbWUiOiJRQSIsInBydF9hZG0iOiJGYWxzZSIsInByZWZlcnJlZF91c2VybmFtZSI6ImNvZGVzY2llbmNlcWEiLCJuYW1lIjoiY29kZXNjaWVuY2VxYSIsInNjb3BlIjpbImVtYWlsIiwib3BlbmlkIiwicHJvZmlsZSIsInRlbmFudCIsIk9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiXSwiYW1yIjpbInB3ZCJdfQ.rQfDqz83R5qujADvcEBhSKREDCrW_L3LwCeRDlSf1NIpIykyCjTdprPp7QgbOmB5FRf7H1778ZY3pkPY4C_EH60lTqraNKe66E09vTpRPlASQoWrbUprNSxkVd7KLTQ16QUthelVsml_D39uSCBfhiUJR0N4Bpr9GF5IVsGOuRgwQtXiw4Gi-7hlWBX5qhnj3GO29uVO5oiSJJtKlMTqWO8iIZloURFdVxYUpXuywH6nEmeUFdIvOsUcFKjPOkpUW2SdIPqWjy7yTplAXoXny1yKBfPbEkwtivvOrzRz6fz6rPQO8qNTKcAf28oeO2iLYWRN7u4AIKLgPdpkbXjwgrrVXgY3Duvw6yjBsC2Yt9Iu6DJMXq2ereBA9E_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.
result = CkJsonObject_stringOf(jResp,"result");
targetUrl = CkJsonObject_stringOf(jResp,"targetUrl");
success = CkJsonObject_BoolOf(jResp,"success");
error = CkJsonObject_stringOf(jResp,"error");
unAuthorizedRequest = CkJsonObject_BoolOf(jResp,"unAuthorizedRequest");
v__abp = CkJsonObject_BoolOf(jResp,"__abp");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
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.0"
},
{
"key": "Date",
"value": "Fri, 09 Apr 2021 13:27:46 GMT"
}
],
"cookie": [
],
"body": "{\n \"result\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6IjVENzg4QTgyMEE4QzAzMkJBNzg1Mjk4QjNBMTlEMkNGMEQyODI2ODYiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJYWGlLZ2dxTUF5dW5oU21MT2huU3p3MG9Kb1kifQ.eyJuYmYiOjE2MTc5NzQ1NjYsImV4cCI6MTYxNzk3ODQ2NiwiaXNzIjoiaHR0cHM6Ly9wdGFvcmNoMjAxMC1pcy5henVyZXdlYnNpdGVzLm5ldC9pZGVudGl0eSIsImF1ZCI6Ik9yY2hlc3RyYXRvckFwaVVzZXJBY2Nlc3MiLCJjbGllbnRfaWQiOiI0ZDdmMmJmMi05MDkzLTQ5NTktOWQ1Mi1iNGE2NjBmMTQ4NWYiLCJzdWIiOiJkNGFiODFlNi00NjU5LTRjMjUtOGFjNy0wYTQ4MGFhZTE3ZjAiLCJhdXRoX3RpbWUiOjE2MTc5NzQ4NjYsImlkcCI6ImxvY2FsIiwiQXNwTmV0L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RgHUsC2cGSo-UGZdCrgX5J4za5b3ze9OoAY\",\n \"targetUrl\": null,\n \"success\": true,\n \"error\": null,\n \"unAuthorizedRequest\": false,\n \"__abp\": true\n}"
}
]
}