Penggunaan Dasar
Request Sederhana
curl https://example.com # GET request curl -o file.html https://url # save to file curl -O https://url/file.tar.gz # save with remote name curl -L https://url # follow redirects
Flag Umum
-sMode silent (tanpa progress)
-STampilkan error dalam mode silent
-fGagal diam-diam pada error HTTP
-LIkuti redirect
-o fileTulis output ke file
-OSimpan dengan nama file remote
-C -Lanjutkan unduhan yang terputus
--max-time 30Timeout setelah 30 detik
HTTP Method
GET & HEAD
curl https://api.example.com/users curl -I https://example.com # HEAD (headers only) curl -i https://example.com # include response headers
POST
curl -X POST https://api.example.com/users \ -H "Content-Type: application/json" \ -d '{"name":"Jo","email":"[email protected]"}'
PUT & PATCH & DELETE
curl -X PUT https://api.example.com/users/1 \ -d '{"name":"Updated"}' curl -X PATCH https://api.example.com/users/1 \ -d '{"email":"[email protected]"}' curl -X DELETE https://api.example.com/users/1
Header
Mengatur Header
curl -H "Content-Type: application/json" URL curl -H "Accept: text/html" URL curl -H "X-Custom: value" URL curl -H "Header1: v1" -H "Header2: v2" URL
Header Response
-iSertakan header response dalam output
-IAmbil header saja (HEAD)
-D fileDump header response ke file
-w '%{http_code}'Cetak HTTP status code
Autentikasi
Basic & Token Auth
curl -u user:pass https://api.example.com curl -H "Authorization: Bearer TOKEN" URL curl -u user:pass --digest URL curl --negotiate -u : URL # Kerberos/SPNEGO
Metode Auth
-u user:passAutentikasi Basic
--digestHTTP Digest auth
--negotiateKerberos/SPNEGO auth
--ntlmAutentikasi NTLM
-nGunakan kredensial ~/.netrc
Data & Form
Mengirim Data
curl -d "key=val&key2=val2" URL # form urlencoded curl -d @data.json URL # data from file curl --data-raw '{"raw":"json"}' URL curl --data-urlencode "q=hello world" URL
Upload File
curl -F "[email protected]" URL curl -F "[email protected];type=application/pdf" URL curl -F "field=value" -F "[email protected]" URL
Multipart vs URL-Encoded
-dapplication/x-www-form-urlencoded
-Fmultipart/form-data
--jsonShorthand: set Content-Type + Accept ke JSON
-T fileUpload file via PUT
SSL/TLS
Opsi Sertifikat
curl --cacert ca.pem URL # custom CA bundle curl --cert client.pem URL # client certificate curl --cert client.pem --key key.pem URL curl -k URL # skip TLS verify (dev only)
Flag TLS
-k / --insecureLewati verifikasi sertifikat TLS
--cacert fileGunakan CA sertifikat kustom
--cert fileSertifikat client
--key filePrivate key client
--tlsv1.2Paksa minimum TLS 1.2
--tlsv1.3Paksa minimum TLS 1.3
Output & Debugging
Verbose & Trace
curl -v URL # verbose output curl --trace dump.txt URL # full trace to file curl --trace-ascii - URL # trace to stdout curl -w "\n%{http_code}\n" URL # custom output format
Variabel Write-Out
%{http_code}HTTP response status code
%{time_total}Total waktu dalam detik
%{time_connect}Waktu untuk membuat koneksi
%{size_download}Byte yang diunduh
%{speed_download}Kecepatan unduhan rata-rata
%{redirect_url}URL redirect (jika ada)
%{ssl_verify_result}Hasil verifikasi SSL (0 = OK)
Contoh Write-Out
curl -s -o /dev/null -w \ "code: %{http_code}\ntime: %{time_total}s\n" \ https://example.com
Pola Umum
Alur Kerja API
# GET JSON and pipe to jq curl -s https://api.example.com/data | jq '.items[]' # POST JSON with auth curl -s -H "Authorization: Bearer $TOKEN" \ --json '{"key":"val"}' https://api.example.com
Pola Unduhan
# Download with progress bar curl -# -O https://releases.example.com/v2.tar.gz # Resume interrupted download curl -C - -O https://releases.example.com/v2.tar.gz # Download multiple files curl -O https://url/file1 -O https://url/file2
Helper Scripting
# Check if URL is reachable curl -sf -o /dev/null https://example.com && echo OK # Save cookies and reuse curl -c cookies.txt -b cookies.txt URL # Rate-limit request curl --limit-rate 100k URL
Proxy & Jaringan
Pengaturan Proxy
curl -x http://proxy:8080 URL curl -x socks5://proxy:1080 URL curl --proxy-user user:pass -x http://proxy:8080 URL curl --noproxy "*.local,localhost" URL
DNS & Resolve
--resolve host:port:addrPaksa resolusi DNS ke addr
--dns-servers 8.8.8.8Gunakan server DNS kustom
--interface eth0Gunakan interface jaringan tertentu
-4 / -6Paksa IPv4 / IPv6
Konfigurasi & Lanjutan
File Konfigurasi
# ~/.curlrc — default options --silent --location --max-time 30 # Use config file explicitly curl -K myconfig.txt URL
Flag Berguna
--retry 3Coba ulang pada error transien
--retry-delay 2Jeda antar percobaan ulang (detik)
--compressedMinta dan dekompresi gzip/br
--limit-rate 100kThrottle kecepatan transfer
-ZTransfer paralel (curl 7.66+)
--create-dirsBuat direktori path untuk -o