Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
var req = new chilkat.HttpRequest();
var jsonParam1 = new chilkat.JsonObject();
req.AddParam("username",jsonParam1.Emit());
var jsonParam2 = new chilkat.JsonObject();
req.AddParam("password",jsonParam2.Emit());
// resp: HttpResponse
var resp = http.PostUrlEncoded("https://domain.com/accounts/login",req);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
console.log(resp.StatusCode);
console.log(resp.BodyStr);
}
chilkatExample();
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": [
]
}