curl(1)
Transfer data from or to a server using URLs, supporting HTTP, HTTPS, FTP, and many other protocols.
Synopsis
curl [OPTION]... [URL]...Description
curl is a command-line tool for transferring data using URLs. It supports a wide range of protocols including HTTP, HTTPS, FTP, SFTP, LDAP, and more. curl is commonly used for downloading files, testing APIs, submitting forms, and automating web requests in scripts.
By default, curl sends a GET request and outputs the response to stdout. Headers and response data are sent together unless separated with specific flags. curl can handle redirects, cookies, authentication, proxies, and custom headers.
Common options
| Flag | What it does |
|---|---|
-o FILE | Write output to FILE instead of stdout |
-O | Save output to a file named after the remote file |
-X METHOD | Specify HTTP request method (GET, POST, PUT, DELETE, etc.) |
-H HEADER | Add custom header; use multiple times for multiple headers |
-d DATA | Send DATA in POST request body; implies -X POST |
-L | Follow HTTP redirects (3xx responses) |
-u USER:PASS | Use basic authentication with username and password |
-A AGENT | Set User-Agent header |
-b COOKIE | Send cookies or read from file |
-i | Include HTTP headers in output |
-I | Fetch headers only (HEAD request) |
-v | Verbose; show request and response details |
Examples
Fetch and display a webpage
curl https://example.comDownload a file and save it as myfile.html
curl -o myfile.html https://example.comSend a JSON POST request to an API endpoint
curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/endpointAccess a page requiring basic authentication
curl -u username:password https://example.com/secureFollow redirects automatically
curl -L https://example.com/redirectDisplay response headers along with the body
curl -i https://example.comFetch only HTTP headers (useful for checking status codes)
curl -I https://example.comUse cookies from a file and save new cookies to it
curl -b cookies.txt -c cookies.txt https://example.com