Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkHttpRequest req;
HCkJsonObject jsonParam1;
HCkJsonObject jsonParam2;
HCkHttpResponse resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
req = CkHttpRequest_Create();
jsonParam1 = CkJsonObject_Create();
CkHttpRequest_AddParam(req,"username",CkJsonObject_emit(jsonParam1));
jsonParam2 = CkJsonObject_Create();
CkHttpRequest_AddParam(req,"password",CkJsonObject_emit(jsonParam2));
resp = CkHttp_PostUrlEncoded(http,"https://domain.com/accounts/login",req);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkJsonObject_Dispose(jsonParam1);
CkJsonObject_Dispose(jsonParam2);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
CkJsonObject_Dispose(jsonParam1);
CkJsonObject_Dispose(jsonParam2);
}
Curl Command
curl -X POST
--data-urlencode 'username={{username}}'
--data-urlencode 'password={{password}}'
https://domain.com/accounts/login
Postman Collection Item JSON
{
"name": "Login to Anypoint Platform",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"const jar = pm.cookies.jar();\r",
"\r",
"jar.clear(pm.request.url, function (error) {\r",
"\r",
"});\r",
""
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"exec": [
"var data = JSON.parse(responseBody);\r",
"pm.environment.set(\"token\", data.access_token);\r",
"pm.environment.set(\"cookies\", \"_csrf=\" + pm.cookies.get(\"_csrf\") +\r",
" \"; XSRF-TOKEN=\" + pm.cookies.get(\"XSRF-TOKEN\") +\r",
" \"; mulesoft.sess=\" + pm.cookies.get(\"mulesoft.sess\") +\r",
" \"; mulesoft.sess.sig=\" + pm.cookies.get(\"mulesoft.sess.sig\") );\r",
" \r",
"pm.cookies.jar().clear(pm.environment.get(\"url\"));\r",
"const cookieJar = pm.cookies.jar();\r",
"cookieJar.clear(pm.environment.get(\"url\"));"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "{{username}}",
"type": "text"
},
{
"key": "password",
"value": "{{password}}",
"type": "text"
}
],
"options": {
"urlencoded": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/accounts/login",
"host": [
"{{url}}"
],
"path": [
"accounts",
"login"
]
}
},
"response": [
]
}