curl -v --data @payload.txt -H "Content-Type: application/x-www-form-urlencoded" -X POST http://server:8080
where payload.txt contains key-value pairs.
curl can be used to send a compressed HTTP request - HTTP requests are not usually compressed, only the responses are, but the standard does not prohibit setting the Content-Encoding header to gzip, deflate or others and then sending a compressed body.
To send a compressed POST HTTP request, first create a file containing the body that shall be sent, say, request.txt and then compress the file using gzip:
gzip request.txt
For this example, the request.txt file contains POST key-value data such that the request content type will be set to application/x-www-url-form-urlencoded.
The command will create a compressed file request.txt.gz. Afterward, the curl command shall read:
curl -v --data-binary @request.txt.gz "Content-Type: application/x-www-form-urlencoded" -H "Content-Encoding: gzip" -X POST http://server.tld/
where:
-v turns on verbosity,--data-binary @request.txt.gz will send the request.txt.gz file as the request body (mind the @, it is necessary),Content-Type is set to application/x-www-form-urlencoded indicating that the request.txt.gz file contains POST key-value data,Content-Encoding is set to gzip,http://server.tld/| Command Line Aspect | Visual Mnemonic Graft |
|---|---|
-fLOsS | |
The following command:
curl -fLOsS https://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2024.9.1_all.deb
will download the binary file deb-multimedia-keyring_2024.9.1_all.deb to the current directory by using fLOsS as command-line parameters passed to curl.
The parameters -fLOsS carry the following meaning:
-f makes curl fail in case there are errors and to not output any document,-L means to follow any redirects,-O tells curl to save the the body to the current directory,-s makes curl silent,-S makes curl show an error in case the download fails (this combines with -s, as in, be silent if no fail)Whilst the following command:
curl "http://sablier:10000/api/strategies/blocking?group=selenium&session_duration=5m&timeout=5m"
is a perfectly valid GET request, it looks messy given that the HTTP parameters are all appended to the URL which makes it such that the line cannot be broken up into smaller pieces.
An elegant equivalent that transposes the HTTP GET request parameters to individual cURL command parameters would be:
curl \ -G \ --data-urlencode "group=selenium" \ --data-urlencode "session_duration=5m" \ --data-urlencode "timeout=5m" \ "http://sablier:10000/api/strategies/blocking"
where:
-G stands for an HTTP GET requestwith the additional bonus that now parameters can be properly URL encoded.