mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
4.2 KiB
4.2 KiB
cURL
Table of contents
TL;DR
# Send single GET requests and show their output on stdout.
curl 'http://url.of/file'
curl 'https://www.example.com'
# Be quiet.
curl … --silent
curl … -s --show-error
# Download files to specific paths.
curl … --output 'path/to/file'
curl … -o 'path/to/file'
# Download files reusing their name for output.
curl … --remote-name 'http://url.of/file1' -O 'http://url.of/file2'
curl … -O http://url.of/file[1-24]
# Resume downloads.
curl … --continue-at -
curl … -o 'partial_file' -C -
# Limit downloads bandwidth.
curl … --limit-rate '1000B'
# Follow redirects.
curl … --location
curl … -L
# Only fetch the response's HTTP headers.
# Prevents downloading the response's body.
curl … --head
curl … -I
# Write specific information in output.
curl … … --write-out '@template.file'
curl … -w 'request returned %{http_code}\nDownloaded %{size_download} bytes\n'
# Send different request types.
curl … --request 'PUT'
curl … -X 'GET'
# Specify headers.
curl … -H 'Content-Type:application/json'
curl … --header 'Content-Type:application/json'
# Fail fast with no output.
# Returns the HTTP error code.
curl … --fail
curl … -f
# Skip certificate validation.
curl … --insecure
curl … -k
# Pass certificates for a resource.
curl … --cert 'client.pem' --key 'key.pem'
curl … --cacert 'ca.pem'
# Authenticate.
curl 'http://url.of/file' --user 'username':'password'
curl 'ftp://url.of/file' -u 'username':'password' -O
curl 'ftp://username:password@example.com'
# Send data.
curl … -X 'POST' -H "Content-Type:application/json" --data '@file.json'
curl … -d '{"name": "bob"}'
curl … -d 'name=bob'
# POST to forms.
curl … --form 'name=user' -F 'password=test'
curl … -d 'name=bob' -F 'password=@password.file'
# Use proxies.
curl … --proxy 'socks5://localhost:19999'
# Forcefully resolve hosts to given addresses.
# The resolution *must* be an address, not an FQDN.
curl … --resolve 'super.fake.domain:8443:127.0.0.1' 'https://super.fake.domain:8443'
# Use different names.
# Kinda like '--resolve' but to aliases and supports ports.
curl … --connect-to 'super.fake.domain:443:localhost:8443' 'https://super.fake.domain'
# Ask kindly to use HTTP/2.
curl … --http2
# Force the use of HTTP/2.
curl … --http2-prior-knowledge
Apply settings to all connections
Unless the -q option is used, curl always checks for a default config file on invocation and uses it if found.
The default configuration file is looked for in the following places, in this order:
$CURL_HOME/.curlrc$XDG_CONFIG_HOME/.curlrc, added in 7.73.0$HOME/.curlrc- on Windows only:
%USERPROFILE%\.curlrc - on Windows only:
%APPDATA%\.curlrc - on Windows only:
%USERPROFILE%\Application Data\.curlrc
On Non-Windows hosts, curl uses getpwuid to find the user's home directory.
On Windows, if curl finds no .curlrc file in the sequence described above, it will check for one in the same dir the
curl executable is placed.
# ~/.curlrc
# Accepts both short and long options.
# Options in long format are accepted without the leading two dashes to make it
# easier to read.
# Arguments must be provided on the same line of the option.
# Arguments can be separated by space, '=' and ':'
location
--insecure
--user-agent "my-agent"
request = "PUT"
config: "~/.config/curl"