Mastering curl: Essential Command‑Line Options for HTTP Requests
This guide provides a concise reference of curl’s most useful command‑line switches—including -A, -b, -c, -d, --data-urlencode, -e, -F, -G, -H, -i, -I, -k, -L, --limit-rate, -o, -O, -s, -S, -u, -v, -x and -X—showing how each option modifies request headers, data handling, authentication, proxying, debugging, and output handling for web interactions.
curl is a versatile command‑line tool for performing HTTP requests, acting as a URL client. Its extensive set of options lets you replace graphical tools like Postman for tasks such as setting headers, sending data, handling cookies, and debugging network traffic.
-A (User‑Agent)
Specifies the User-Agent header. The default is 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 omit the header, or set it via -H 'User-Agent: …'.
-b (Send Cookie)
Sends a Cookie header. Examples:
$ curl -b 'foo=bar' https://google.com $ curl -b 'foo1=bar' -b 'foo2=baz' https://google.com $ curl -b cookies.txt https://www.google.comThe last command reads cookies from a local cookies.txt file (created with -c).
-c (Save Cookie)
Writes server‑set cookies to a file:
$ curl -c cookies.txt https://www.google.com-d (POST Data)
Sends data in a POST request. The Content‑Type header is set to application/x-www-form-urlencoded automatically, and the request method becomes POST, so -X POST can be omitted.
$ curl -d 'login=emma&password=123' -X POST https://google.com/login $ curl -d '@data.txt' https://google.com/login--data-urlencode
Like -d but URL‑encodes the data before sending:
$ curl --data-urlencode 'comment=hello world' https://google.com/login-e (Referer)
Sets the HTTP Referer header:
$ curl -e 'https://google.com?q=example' https://www.example.comThe same effect can be achieved with -H 'Referer: …'.
-F (Multipart Form)
Uploads binary files using multipart/form-data:
$ curl -F '[email protected]' https://google.com/profileYou can specify the MIME type or a different filename:
$ curl -F '[email protected];type=image/png' https://google.com/profile $ curl -F '[email protected];filename=me.png' https://google.com/profile-G (GET with Data)
Appends data as a query string to the URL, turning a POST‑style -d into a GET request:
$ curl -G -d 'q=kitties' -d 'count=20' https://google.com/search-H (Custom Header)
Adds arbitrary HTTP headers:
$ curl -H 'Accept-Language: en-US' https://google.com $ curl -H 'Content-Type: application/json' -d '{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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
