make web requests with curl
Send GET and POST requests, JSON and files, see headers and status codes, go through a proxy.
Steps
-
curl -sS https://example.coma page, without the progress bar, errors still shown
-
curl -I https://example.comonly the headers
-
curl -s -o /dev/null -w '%{http_code}\n' https://example.comonly the status code
-
curl -X POST -H 'Content-Type: application/json' -d '{"name":"x"}' https://api.example.com/itemspost JSON
-
curl -F '[email protected]' https://example.com/uploadupload a file as a form
-
curl -u NAME:password https://example.comwith a user and password
-
curl -x http://proxy:8080 https://example.comthrough a proxy
-
curl -L -o file.zip https://example.com/file.zipdownload, following redirects
Notes
- -v shows everything sent and received, to find out why a request fails.
Commands used
curlwget
Each has a page in lore: lore curl opens it.
Related recipes
- ask for input in a scriptAsk yes or no, read a password without showing it, or wait for an answer with a time limit.
- check a certificateSee a site's TLS certificate, when it expires and who issued it, or the same for a .pem file.
- check if a file or folder existsTest in a script whether a path exists, is a file, a folder, empty or runnable.
- check if a string contains a textTest in a script whether a string contains, starts with or matches something.