make web requests with curl

Send GET and POST requests, JSON and files, see headers and status codes, go through a proxy.

  • network
  • development

Steps

  1. curl -sS https://example.com

    a page, without the progress bar, errors still shown

  2. curl -I https://example.com

    only the headers

  3. curl -s -o /dev/null -w '%{http_code}\n' https://example.com

    only the status code

  4. curl -X POST -H 'Content-Type: application/json' -d '{"name":"x"}' https://api.example.com/items

    post JSON

  5. curl -F '[email protected]' https://example.com/upload

    upload a file as a form

  6. curl -u NAME:password https://example.com

    with a user and password

  7. curl -x http://proxy:8080 https://example.com

    through a proxy

  8. curl -L -o file.zip https://example.com/file.zip

    download, following redirects

Notes

  • -v shows everything sent and received, to find out why a request fails.

Commands used

  • curl
  • wget

Each has a page in lore: lore curl opens it.