Living in the Shell #17; curl (HTTP/S Client) (Part 2)
Babak K. Shandiz
Posted on December 16, 2021
curl
đ
Makes requests in various protocols, including (but not limited to) HTTP/HTTPS/FTP/FTPS.
Add a custom header to request -H
curl https://postman-echo.com/get -H 'user-agent: curl'
âšī¸ You can set any number of headers by repeating
-H
options.
Make a POST
request with JSON body -d
& -X
curl https://postman-echo.com/post \
-X POST \
-H 'content-type: application/json' \
-d '{"key":"value"}'
{ "args": {}, "data": { "key": "value" }, "files": {}, "form": {}, "headers": { "x-forwarded-proto": "https", "x-forwarded-port": "443", "host": "postman-echo.com", "x-amzn-trace-id": "Root=1-61ba2f8f-304430e917ea20e7024a87c3", "content-length": "15", "user-agent": "curl/7.74.0", "accept": "*/*", "content-type": "application/json" }, "json": { "key": "value" }, "url": "https://postman-echo.com/post" }
Read request body from file -d@
curl https://postman-echo.com/post \
-X POST \
-H 'content-type: application/json' \
-d @data-file.json
Read request headers from file -H@
curl https://postman-echo.com/post \
-X POST \
-H @headers-file.txt \
-d @data-file.json
â ī¸ The headers file should be formatted as "key: value" per line.
Make a HEAD
request -I
curl -I https://postman-echo.com/get
âšī¸ Alternatively, you can use
-X HEAD
instead of-I
.
See more detailed process logs -v
curl -v https://postman-echo.com/get
This will print more low-level details, including protocol handshakes and negotiations.
đ đĒ đ
đŠ
Babak K. Shandiz
Posted on December 16, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.