cURL
stands for Client URL
, it is a command-line tool for getting or sending
data including files using URL syntax. Since cURL
uses libcurl
, it supports
a range of common network protocols, currently including HTTP, HTTPS, FTP, FTPS,
SCP, SFTP, TFTP, LDAP, DAP, DICT, TELNET, FILE, IMAP, POP3, SMTP and RTSP.
Here is a open-source book: Everything curl
About curl
proxy environment variables(see man for more details):
http_proxy
(only be lower case) to specify http proxy.https_proxy
to specify https proxy (curl to proxy over ssl/tls).NO_PROXY
or--noproxy '*'
to skip proxy use for all hosts, or a list for some hosts.
When using curl
download files, make sure it actually downloads it rather than
the HTML page, you can check the file type via file
command, for example:
1 | curl -Ss <URL> -o xxx.tar.gz |
If the URL is wrong, curl
will download the HTML page instead. wget
will
show 404 error and fail.
Date and Note
1 | 05/23/2019 download file |
05/23/2019
If the file server needs user name/password (usually will prompt when you open in browser).
1 | # -O: downloads the file and saves it with the same name as in the URL. |
If you don’t turn off the certificate check(-k
), you will get error message
and fail:
1 | curl: (60) Peer's Certificate has expired. |
06/16/2019
When I was working on
Docker Registry API,
I primarily used curl
to do the job.
1 | # -v: Makes the fetching more verbose/talkative. Mostly useful for debugging. A |
06/22/2020
1 | # -L: redirect |
09/02/2020
Add additional headers, only show header info:
1 | # -H,--header: add header |
09/03/2020
Using HTTP proxy (forward) with proxy authentication, learned from Envoy.
1 | # -x, --proxy: use the specific forward proxy |
Default to use basic authentication scheme, Some proxies will require another
authentication scheme (and the headers that are returned when you get a 407
response will tell you which).
1 | ## --proxy-anyauth: ask curl to use any method the proxy wants |
09/06/2020
Resume the download:
1 | curl <url> -o archive |
09/07/2020
Download/upload speed limit if you have a limit bandwidth.
1 | # limit rate as 1m/second, for example: 10k, 1g |
09/08/2020
Only fetch header information, no body:
1 | # -I,--head: (HTTP FTP FILE) Fetch the headers only! |
09/09/2020
Non-HTTP protocols over HTTP proxy Most HTTP proxies allow clients to “tunnel through” it to a server on the other side. That’s exactly what’s done every time you use HTTPS through the HTTP proxy.
1 | # -p, --proxytunnel: make curl tunnel through the proxy |
10/25/2020
The curl with name resolve tricks and another post about it.
This feature is primarily used for HTTP server development and testing the server locally to mimic real world situations.
1 | # First start a simple http server within python virtualenv: |
1 | # Override the default Host header otherwise the Host header value |
04/07/2022
Retry until reaching condition limits:
1 | # --retry: worked on a timeout, an FTP 4xx response code or an HTTP 408, 429, |
04/01/2023
For example, the POST request is like:
1 | curl -vs -X POST \ |
Regardless of the format in payload.json
, curl
will always remove the line
returns and one-line the JSON content and send it, which is different from
Postman who will send payload with line returns (which could be identified as
security issue by firewall rules).
04/03/2023
To check the request payload sent, use --trace-ascii
:
1 | curl -vs -X POST \ |