Οδηγός cURL
Ένας οδηγός αναφοράς curl με δυνατότητα αναζήτησης και εκτύπωσης — μέθοδοι HTTP, κεφαλίδες, δεδομένα και φόρμες, ταυτοποίηση, λήψεις, cookies, TLS, διακομιστές μεσολάβησης και αποσφαλμάτωση. Δωρεάν.
Basics
12curl https://api.example.com
curl -o page.html https://example.com
curl -O https://example.com/file.zip
curl -i https://example.com
curl -I https://example.com
curl -v https://example.com
curl -s https://example.com
curl -sS https://example.com
curl -L https://example.com
curl https://a.com https://b.com
curl 'https://x.com/p?[1-5]'
curl --version
HTTP methods
9curl -X GET https://api.example.com
curl -X POST https://api.example.com
curl -X PUT https://api.example.com/1
curl -X PATCH https://api.example.com/1
curl -X DELETE https://api.example.com/1
curl -I https://api.example.com
curl -X OPTIONS https://api.example.com
curl --head https://api.example.com
curl --request POST https://x.com
Headers
10curl -H 'Accept: application/json' https://x.com
curl -H 'X-Token: abc' -H 'X-Env: dev' https://x.com
curl -H 'Content-Type: application/json' https://x.com
curl -H 'Authorization: Bearer TOKEN' https://x.com
curl -H 'Host: example.com' https://1.2.3.4
curl -H 'Accept-Encoding: gzip' https://x.com
curl -A 'MyAgent/1.0' https://x.com
curl -e 'https://ref.com' https://x.com
curl -H 'X-Debug:' https://x.com
curl --compressed https://x.com
Sending data
11curl -d 'name=Jane&age=30' https://x.com
curl -d '@payload.json' https://x.com
curl --data-urlencode 'q=hello world' https://x.com
curl --data-binary '@file.bin' https://x.com
curl -G --data-urlencode 'q=cats' https://x.com
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Jane"}' https://x.com
curl --json '{"name":"Jane"}' https://x.com
curl -F 'name=Jane' https://x.com
curl -F 'file=@photo.png' https://x.com
curl -F 'file=@a.pdf;type=application/pdf' https://x.com
curl -d '' https://x.com
Authentication
9curl -u user:pass https://x.com
curl -u user https://x.com
curl -H 'Authorization: Bearer TOKEN' https://x.com
curl --oauth2-bearer TOKEN https://x.com
curl --digest -u user:pass https://x.com
curl --ntlm -u user:pass https://x.com
curl --netrc https://x.com
curl --netrc-file creds https://x.com
curl -H 'X-Api-Key: KEY' https://x.com
Downloading & uploading
11curl -O https://x.com/file.zip
curl -o out.zip https://x.com/file.zip
curl -OL https://x.com/file.zip
curl -C - -O https://x.com/file.zip
curl --limit-rate 200k -O https://x.com/f
curl -r 0-1023 -o part https://x.com/f
curl --retry 3 -O https://x.com/f
curl -T file.txt ftp://x.com/
curl -T file.txt https://x.com/up
curl --create-dirs -o a/b/f.txt https://x.com
curl -# -O https://x.com/file.zip
Cookies
8curl -b 'session=abc123' https://x.com
curl -b cookies.txt https://x.com
curl -c cookies.txt https://x.com
curl -b jar.txt -c jar.txt https://x.com
curl -b 'a=1; b=2' https://x.com
curl -c - https://x.com
curl --junk-session-cookies -b jar.txt https://x.com
curl -L -c jar.txt -b jar.txt https://x.com/login
TLS / SSL
10curl -k https://x.com
curl --cacert ca.pem https://x.com
curl --capath /etc/ssl/certs https://x.com
curl --cert client.pem https://x.com
curl --cert client.pem --key client.key https://x.com
curl --tlsv1.2 https://x.com
curl --tlsv1.3 https://x.com
curl --tls-max 1.2 https://x.com
curl --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://x.com
curl -vI https://x.com
Proxies
9curl -x http://proxy:8080 https://x.com
curl --proxy http://proxy:8080 https://x.com
curl -x proxy:8080 -U user:pass https://x.com
curl --proxy-user user:pass -x proxy:8080 https://x.com
curl --socks5 127.0.0.1:1080 https://x.com
curl --socks5-hostname 127.0.0.1:1080 https://x.com
curl --socks4 127.0.0.1:1080 https://x.com
curl --noproxy example.com https://x.com
curl -x '' https://x.com
Debugging & output
11curl -w '%{http_code}\n' -o /dev/null -s https://x.com
curl -w '%{time_total}\n' -o /dev/null -s https://x.com
curl -w '@format.txt' https://x.com
curl -D headers.txt https://x.com
curl -D - -o body.txt https://x.com
curl --trace trace.txt https://x.com
curl --trace-ascii - https://x.com
curl --trace-time -v https://x.com
curl -v https://x.com 2>&1 | less
curl -sS -o /dev/null -w '%{size_download}\n' https://x.com
curl --libcurl out.c https://x.com
Timeouts & retries
10curl --connect-timeout 5 https://x.com
curl --max-time 30 https://x.com
curl --retry 3 https://x.com
curl --retry 3 --retry-delay 2 https://x.com
curl --retry 5 --retry-max-time 60 https://x.com
curl --retry-connrefused https://x.com
curl --retry-all-errors https://x.com
curl --speed-limit 100 --speed-time 10 https://x.com
curl --keepalive-time 60 https://x.com
curl --expect100-timeout 1 https://x.com
Καμία καταχώριση δεν ταιριάζει με «:q».
Σχετικά με το Οδηγός cURL
Αυτό το φύλλο εξαπάτησης για curl είναι μια πρακτική αναφορά για το πιο χρήσιμο εργαλείο γραμμής εντολών HTTP: βασικά, μέθοδοι HTTP, κεφαλίδες, αποστολή δεδομένων, ταυτοποίηση, λήψη και μεταφόρτωση, cookies, TLS/SSL, proxies, εντοπισμός σφαλμάτων και έξοδος, και χρονικά όρια και επαναλήψεις.
Το curl έχει εκατοντάδες σημαίες και όλοι θυμούνται περίπου δέκα από αυτές. Κάθε γραμμή δείχνει μία πλήρη εντολή — ένα POST με JSON, μια παράκαμψη κεφαλίδας, μια λήψη με δυνατότητα συνέχισης, μια αναλυτική διαπραγμάτευση TLS — με μια σύντομη περιγραφή, ώστε να παίρνετε την ακριβή μαγική φράση αντί να διαβάζετε μια σελίδα εγχειριδίου εν μέσω εντοπισμού σφαλμάτων.
Το φύλλο είναι δωρεάν και από την πλευρά του client: φιλτράρετε τις εντολές ζωντανά με το πλαίσιο αναζήτησης, μεταβείτε μεταξύ ενοτήτων από τον κολλημένο πίνακα περιεχομένων, αντιγράψτε οποιαδήποτε εντολή με ένα κλικ και εκτυπώστε τη σελίδα για συνεδρίες εντοπισμού σφαλμάτων API.
Πώς να χρησιμοποιήσετε το Οδηγός cURL
- Εξετάστε τις ενότητες, από τα Βασικά και τις μεθόδους HTTP έως τον Εντοπισμό σφαλμάτων & έξοδο και τα Χρονικά όρια & επαναλήψεις.
- Αναζητήστε μια σημαία ή εργασία όπως POST, header ή proxy για άμεσο φιλτράρισμα των εντολών.
- Μεταβείτε σε μια ενότητα όπως Ταυτοποίηση ή TLS / SSL μέσω της κολλημένης πλαϊνής μπάρας.
- Κάντε κλικ σε μια εντολή ή στο εικονίδιο αντιγραφής της για να την αντιγράψετε, και μετά αντικαταστήστε το URL και τις τιμές του παραδείγματος.
- Εκτυπώστε το φύλλο για να κρατήσετε μια αναφορά curl δίπλα στο τερματικό σας.