make web requests with curl
Send GET and POST requests, JSON and files, see headers and status codes, go through a proxy.
networkdevelopment
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 'file=@photo.jpg' 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.
ask for input in a script
Ask yes or no, read a password without showing it, or wait for an answer with a time limit.
check a certificate
See 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 exists
Test in a script whether a path exists, is a file, a folder, empty or runnable.
check if a string contains a text
Test in a script whether a string contains, starts with or matches something.