Improve bash implementation

This commit is contained in:
Maurits van der Schee 2017-03-05 10:17:52 +01:00
commit 8deb13d824

View file

@ -1,12 +1,12 @@
#!/bin/bash
# login and store cookies in 'cookies.txt'
curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt --silent >/dev/null
# login and store cookies in 'cookies.txt' AND retrieve the value of the XSRF token
TOKEN=`curl 'http://localhost/api.php/' --data "username=admin&password=admin" --cookie-jar cookies.txt`
# retrieve the value of the 'XSRF-TOKEN' cookie
TOKEN=`cat cookies.txt|grep XSRF-TOKEN|cut -f 7`
# strip the double quotes from the variable (JSON decode)
TOKEN=${TOKEN//\"/}
# set the 'XSRF-TOKEN' as the 'X-XSRF-Token' header AND send the cookies to the server
# set the XSRF token as the 'X-XSRF-Token' header AND send the cookies to the server
curl 'http://localhost/api.php/posts?include=categories,tags,comments&filter=id,eq,1' --header "X-XSRF-Token: $TOKEN" --cookie cookies.txt
# clean up