پاسخ کوتاه
پنج الگوی پرکاربرد: ۱) `curl -sI https://site` — فقط هدرها و کد وضعیت؛ ۲) `curl --json '{"a":1}' https://api/x` — ارسال JSON (نسخههای جدید curl)؛ ۳) `-w` با متغیرهای زمان — زمان DNS، اتصال، TLS و TTFB را جدا نشان میدهد؛ ۴) `--resolve example.ir:443:1.2.3.4` — آزمون سرور جدید پیش از تغییر DNS؛ ۵) `-v` برای دیدن کامل handshake و هدرها. `-k` (نادیده گرفتن خطای گواهی) فقط برای آزمون موقت؛ هرگز در اسکریپت production. توکنها را در تاریخچه shell نگذارید؛ از متغیر محیطی استفاده کنید.
API و احراز
مستندات curl manual. کدهای پاسخ در کدهای وضعیت HTTP.
curl -s https://api.example.ir/v1/servers -H "Authorization: Bearer $TOKEN" | jq .curl -s -X POST https://api.example.ir/v1/servers -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" -d '{"name":"web-1","plan":"vps-2"}'curl --json '{"name":"web-1"}' https://api.example.ir/v1/servers # curl 7.82+curl -X PATCH ... ; curl -X DELETE https://api.example.ir/v1/servers/42curl -u admin:"$PASS" https://example.ir/admincurl -F "file=@report.pdf" -F "title=Q4" https://api.example.ir/uploadcurl -d "user=ali&pass=..." https://example.ir/login # فرمcurl -c cookies.txt -b cookies.txt https://example.ir/dashboardزمانبندی و DNS
اندازهگیری TTFB در اندازهگیری TTFB.
curl -o /dev/null -s -w "dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} code=%{http_code} size=%{size_download}\n" https://example.ir/ # آزمون سرور جدید بدون تغییر DNScurl -sI --resolve example.ir:443:203.0.113.20 https://example.ir/curl -sI --connect-to example.ir:443:new-server.internal:443 https://example.ir/ curl -sIL http://example.ir # دنبال کردن زنجیره ریدایرکتcurl -s -o /dev/null -w "%{redirect_url}\n" http://example.ircurl -sI --compressed https://example.ir | grep -i content-encodingcurl -sI --http2 https://example.ir | head -1دانلود، TLS و پروکسی
TLS در پیکربندی TLS و OpenSSL. ضبط بسته در tcpdump.
curl -LO https://example.ir/file.isocurl -C - -O https://example.ir/file.iso # ادامه دانلودcurl --retry 5 --retry-delay 3 --retry-all-errors -O https://example.ir/filecurl --limit-rate 1M -O https://example.ir/big curl -v https://example.ir 2>&1 | grep -E "SSL connection|subject|expire|issuer"curl --cacert internal-ca.pem https://internal.example.ircurl --cert client.pem --key client.key https://mtls.example.ircurl -x http://proxy.internal:3128 https://example.ircurl --noproxy "*.internal" https://api.internalسوالات متداول
-k امن است؟ نه؛ فقط برای آزمون موقت.
خروجی JSON خوانا؟ | jq .
HTTP/3؟ با build پشتیبان و --http3.
آخرین بازبینی: آذر ۱۴۰۵ — تیم فنی هاستیفای
تصویر کاور: Carlos Valenzuela، مجوز CC BY-SA 4.0، از ویکیمدیا کامنز


