Curl with Cookies and Headers
Every now and then I find myself needing to make an http request with specific cookies and headers to help debug an issue. And every time I resort to the curl manpage and try a few times until I get the right incantation. So, to save myself time in the future, here is an example:
curl -v --cookie "cookieName=cookieValue" --header "Accept-Language: en" --header "X-Forwarded-For: 184.108.40.206" "http://localhost:8080/somepage"
Tells curl to be verbose, useful for seeing if your headers are being sent.
- --cookie "cookieName=cookieValue"
Tells curl to send the cookie header with the given value. Multiple cookies can be sent using "cookieName1=cookieValue1;cookieName2=cookieValue2".
- --header "headerName: headerValue"
Tells curl to add the header line you specified. You can send multiple headers by giving multiple --header arguments (see above).
The ability to hand-craft HTTP requests is a great feature of curl and makes it a great debugging tool.