Master curl: Essential Command-Line Tricks for HTTP Requests
This guide provides a concise reference of curl’s most commonly used command-line options—including setting user agents, handling cookies, sending POST data, uploading files, managing redirects, limiting bandwidth, and debugging—offering developers a quick cheat‑sheet to replace graphical tools like Postman.
curl is a widely used command-line tool for making HTTP requests; its name stands for client URL.
It offers many powerful options that can replace graphical tools like Postman.
This article lists the most important curl command-line options for quick reference.
-A
The -A option sets the User-Agent header. By default curl uses curl/[version]. Example:
$ curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.comUse -A '' to remove the User-Agent header, or -H 'User-Agent: php/1.0' to set it directly.
-b
The -b option sends cookies to the server. $ curl -b 'foo=bar' https://google.com Multiple cookies can be sent:
$ curl -b 'foo1=bar;foo2=bar2' https://google.comRead cookies from a file:
$ curl -b cookies.txt https://www.google.com-c
The -c option writes received cookies to a file.
$ curl -c cookies.txt https://www.google.com-d
The -d option sends data in the request body, typically for POST requests.
$ curl -d 'login=emma&password=123' -X POST https://google.com/loginMultiple -d arguments are combined, and -d '@data.txt' reads data from a file.
--data-urlencode
Similar to -d but URL‑encodes the data.
$ curl --data-urlencode 'comment=hello world' https://google.com/login-e
Sets the Referer header.
$ curl -e 'https://google.com?q=example' https://www.example.comEquivalent to -H 'Referer: …'.
-F
Uploads files using multipart/form‑data.
$ curl -F '[email protected]' https://google.com/profileSpecify MIME type or filename with ;type=… or ;filename=….
-G
Turns data into a query string for a GET request.
$ curl -G -d 'q=kitties' -d 'count=20' https://google.com/search-H
Adds arbitrary HTTP headers.
$ curl -H 'Accept-Language: en-US' https://google.comMultiple headers can be added, and JSON payloads can be sent with -H 'Content-Type: application/json'.
-i
Includes response headers in the output.
$ curl -i https://www.example.com-I
Sends a HEAD request and shows only the response headers. --head is equivalent.
$ curl -I https://www.example.com-k
Disables SSL certificate verification.
$ curl -k https://www.example.com-L
Follows redirects.
$ curl -L -d 'tweet=hi' https://api.twitter.com/tweet--limit-rate
Limits transfer speed, e.g., --limit-rate 200k caps bandwidth at 200 KB/s.
-o
Saves the response body to a file.
$ curl -o example.html https://www.example.com-O
Saves to a file using the remote name.
$ curl -O https://www.example.com/foo/bar.html-s
Silent mode: no progress or error messages.
$ curl -s https://www.example.com-S
Shows errors only, usually combined with -s.
$ curl -S -s -o /dev/null https://google.com-u
Provides basic authentication credentials. $ curl -u 'bob:12345' https://google.com/login Credentials can also be embedded in the URL.
-v
Verbose mode prints the full request/response exchange for debugging. $ curl -v https://www.example.com The --trace - option outputs raw binary data as well.
-x
Specifies a proxy, e.g., -x socks5://user:pass@proxy:8080 or an HTTP proxy.
$ curl -x socks5://james:[email protected]:8080 https://www.example.com-X
Explicitly sets the HTTP method, such as -X POST. $ curl -X POST https://www.example.com Original link: http://www.ruanyifeng.com/blog/2019/09/curl-reference.html
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
