Cookies And Curl

Curl is the helpful shell command for HTTP requests, and typically I used them to testing a webservice. There are times where I need to send a cookie, and I always end up grepping for the last time I did it.

So here is a simple guide on how to send cookies, along with a headers in your curl command:

curl -X GET --cookie "myCookie=123ABC" -H'Accept: application/json' \
    -H'internalHeader: true'"http://localhost:8080/pages"

As you see, --cookie sets a cookie, with the value following. Headers can be added with -H or --header. And the big difference between the two, cookie key-values are separated with an equals (=), and headers are separated with a colon (:).