เอกสารอ้างอิง curl ที่ค้นหาและพิมพ์ได้——เมธอด HTTP, header, ข้อมูลและฟอร์ม, การยืนยันตัวตน, การดาวน์โหลด, cookie, TLS, proxy และการดีบัก ฟรี

พื้นฐาน

12
curl https://api.example.com
ส่ง request GET และแสดง body
curl -o page.html https://example.com
บันทึก response เป็นไฟล์ที่ตั้งชื่อ
curl -O https://example.com/file.zip
บันทึกโดยใช้ชื่อไฟล์ฝั่ง remote
curl -i https://example.com
แสดง header ของ response พร้อม body
curl -I https://example.com
ดึงเฉพาะ header ของ response (HEAD)
curl -v https://example.com
เอาต์พุตแบบละเอียดของ request/response
curl -s https://example.com
โหมดเงียบ ซ่อน progress และ error
curl -sS https://example.com
เงียบแต่ยังแสดง error
curl -L https://example.com
ตาม HTTP redirect (3xx)
curl https://a.com https://b.com
ขอหลาย URL ในการเรียกเดียว
curl 'https://x.com/p?[1-5]'
ใช้ช่วงตัวเลขวนหลาย URL
curl --version
แสดงเวอร์ชันและฟีเจอร์ของ curl

HTTP method

9
curl -X GET https://api.example.com
ส่ง request GET โดยระบุชัดเจน
curl -X POST https://api.example.com
ส่ง request POST
curl -X PUT https://api.example.com/1
ส่ง request PUT เพื่อแทนที่ resource
curl -X PATCH https://api.example.com/1
ส่ง request PATCH เพื่ออัปเดต field
curl -X DELETE https://api.example.com/1
ส่ง request DELETE
curl -I https://api.example.com
ส่ง request HEAD เพื่อขอเฉพาะ header
curl -X OPTIONS https://api.example.com
ส่ง request OPTIONS preflight
curl --head https://api.example.com
รูปแบบยาวของ -I สำหรับ request HEAD
curl --request POST https://x.com
รูปแบบยาวของ -X เพื่อกำหนด method

Header

10
curl -H 'Accept: application/json' https://x.com
เพิ่ม header ของ request หนึ่งตัว
curl -H 'X-Token: abc' -H 'X-Env: dev' https://x.com
เพิ่มหลาย header
curl -H 'Content-Type: application/json' https://x.com
ประกาศ content type ของ body
curl -H 'Authorization: Bearer TOKEN' https://x.com
ส่ง header authorization แบบ bearer
curl -H 'Host: example.com' https://1.2.3.4
แทนที่ header Host
curl -H 'Accept-Encoding: gzip' https://x.com
ขอ response บีบอัดแบบ gzip
curl -A 'MyAgent/1.0' https://x.com
ตั้งค่า string User-Agent
curl -e 'https://ref.com' https://x.com
ตั้งค่า header Referer
curl -H 'X-Debug:' https://x.com
ลบ header เริ่มต้นโดยปล่อยว่าง
curl --compressed https://x.com
ขอและคลายบีบอัด response อัตโนมัติ

การส่งข้อมูล

11
curl -d 'name=Jane&age=30' https://x.com
POST ข้อมูลฟอร์มแบบ URL-encoded
curl -d '@payload.json' https://x.com
POST ข้อมูลที่อ่านจากไฟล์
curl --data-urlencode 'q=hello world' https://x.com
POST field แบบ URL-encoded หนึ่งตัว
curl --data-binary '@file.bin' https://x.com
POST ไบต์ดิบโดยไม่ประมวลผล
curl -G --data-urlencode 'q=cats' https://x.com
ต่อข้อมูลเป็น query string ของ GET
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Jane"}' https://x.com
POST body แบบ JSON
curl --json '{"name":"Jane"}' https://x.com
POST JSON และตั้ง header JSON อัตโนมัติ
curl -F 'name=Jane' https://x.com
ส่ง field ฟอร์มแบบ multipart
curl -F 'file=@photo.png' https://x.com
อัปโหลดไฟล์เป็น multipart form-data
curl -F 'file=@a.pdf;type=application/pdf' https://x.com
อัปโหลดไฟล์พร้อมระบุ MIME type
curl -d '' https://x.com
POST ด้วย body ว่าง

การยืนยันตัวตน

9
curl -u user:pass https://x.com
HTTP basic authentication
curl -u user https://x.com
Basic auth ถามรหัสผ่าน
curl -H 'Authorization: Bearer TOKEN' https://x.com
ส่ง header bearer token
curl --oauth2-bearer TOKEN https://x.com
ส่ง bearer token แบบ OAuth 2.0
curl --digest -u user:pass https://x.com
ใช้ HTTP digest authentication
curl --ntlm -u user:pass https://x.com
ใช้ NTLM authentication
curl --netrc https://x.com
อ่าน credential จาก ~/.netrc
curl --netrc-file creds https://x.com
อ่าน credential จากไฟล์ netrc กำหนดเอง
curl -H 'X-Api-Key: KEY' https://x.com
ส่ง header API key

การดาวน์โหลดและอัปโหลด

11
curl -O https://x.com/file.zip
ดาวน์โหลดโดยใช้ชื่อไฟล์ฝั่ง remote
curl -o out.zip https://x.com/file.zip
ดาวน์โหลดเป็นชื่อไฟล์ที่เลือก
curl -OL https://x.com/file.zip
ดาวน์โหลดและตาม redirect
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/
อัปโหลดไฟล์ด้วย PUT/FTP
curl -T file.txt https://x.com/up
อัปโหลดไฟล์ผ่าน HTTP PUT
curl --create-dirs -o a/b/f.txt https://x.com
สร้างไดเรกทอรีที่ขาดสำหรับเอาต์พุต
curl -# -O https://x.com/file.zip
แสดงแถบ progress แบบง่าย

Cookie

8
curl -b 'session=abc123' https://x.com
ส่ง cookie แบบ inline
curl -b cookies.txt https://x.com
ส่ง cookie จากไฟล์
curl -c cookies.txt https://x.com
เขียน cookie ที่ได้รับลง jar
curl -b jar.txt -c jar.txt https://x.com
อ่านและอัปเดต cookie jar เดียวกัน
curl -b 'a=1; b=2' https://x.com
ส่งหลาย cookie พร้อมกัน
curl -c - https://x.com
แสดง cookie ที่ได้รับไปยัง stdout
curl --junk-session-cookies -b jar.txt https://x.com
ละ session cookie จาก jar
curl -L -c jar.txt -b jar.txt https://x.com/login
คง session ข้าม redirect

TLS / SSL

10
curl -k https://x.com
อนุญาตแบบไม่ปลอดภัย (ข้ามตรวจ cert)
curl --cacert ca.pem https://x.com
ตรวจสอบด้วย CA bundle กำหนดเอง
curl --capath /etc/ssl/certs https://x.com
ใช้ไดเรกทอรีของ CA certificate
curl --cert client.pem https://x.com
ส่ง client certificate
curl --cert client.pem --key client.key https://x.com
ใช้ client cert และ private key
curl --tlsv1.2 https://x.com
ต้องการ TLS 1.2 ขึ้นไป
curl --tlsv1.3 https://x.com
ต้องการ TLS 1.3 ขึ้นไป
curl --tls-max 1.2 https://x.com
จำกัดเวอร์ชัน TLS สูงสุด
curl --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://x.com
จำกัด cipher TLS ที่อนุญาต
curl -vI https://x.com
ตรวจสอบรายละเอียด TLS handshake

Proxy

9
curl -x http://proxy:8080 https://x.com
ส่ง request ผ่าน HTTP proxy
curl --proxy http://proxy:8080 https://x.com
รูปแบบยาวของ -x เพื่อตั้ง proxy
curl -x proxy:8080 -U user:pass https://x.com
ยืนยันตัวตนกับ proxy
curl --proxy-user user:pass -x proxy:8080 https://x.com
รูปแบบยาวของ credential proxy
curl --socks5 127.0.0.1:1080 https://x.com
ใช้ SOCKS5 proxy
curl --socks5-hostname 127.0.0.1:1080 https://x.com
SOCKS5 proxy พร้อม resolve DNS ฝั่ง remote
curl --socks4 127.0.0.1:1080 https://x.com
ใช้ SOCKS4 proxy
curl --noproxy example.com https://x.com
ข้าม proxy สำหรับ host ที่กำหนด
curl -x '' https://x.com
ปิด proxy ที่ตั้งค่าไว้ทั้งหมด

การ debug และเอาต์พุต

11
curl -w '%{http_code}\n' -o /dev/null -s https://x.com
แสดงเฉพาะ HTTP status code
curl -w '%{time_total}\n' -o /dev/null -s https://x.com
แสดงเวลาถ่ายโอนรวม
curl -w '@format.txt' https://x.com
อ่านรูปแบบ write-out จากไฟล์
curl -D headers.txt https://x.com
เขียน header ของ response ลงไฟล์
curl -D - -o body.txt https://x.com
header ไป stdout, body ไปไฟล์
curl --trace trace.txt https://x.com
trace แบบ hex เต็มของการถ่ายโอน
curl --trace-ascii - https://x.com
trace แบบ ASCII ไป stdout
curl --trace-time -v https://x.com
เพิ่ม timestamp ในเอาต์พุต verbose
curl -v https://x.com 2>&1 | less
เลื่อนดู log verbose ทีละหน้า
curl -sS -o /dev/null -w '%{size_download}\n' https://x.com
แสดงจำนวนไบต์ที่ดาวน์โหลด
curl --libcurl out.c https://x.com
สร้างซอร์ส C ของ libcurl ที่เทียบเท่า

Timeout และการลองใหม่

10
curl --connect-timeout 5 https://x.com
จำกัดช่วงเชื่อมต่อเป็นวินาที
curl --max-time 30 https://x.com
จำกัดเวลาทั้งหมดของการทำงาน
curl --retry 3 https://x.com
ลองใหม่เมื่อเกิด error ชั่วคราว
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
ลองใหม่เมื่อ connection refused ด้วย
curl --retry-all-errors https://x.com
ลองใหม่ทุก error ไม่ใช่แค่ชั่วคราว
curl --speed-limit 100 --speed-time 10 https://x.com
ยกเลิกหากช้าเกินตามเวลาที่กำหนด
curl --keepalive-time 60 https://x.com
ตั้งช่วง keep-alive ของ TCP
curl --expect100-timeout 1 https://x.com
จำกัดการรอ 100-continue

ไม่มีรายการที่ตรงกับ “:q”


แชร์สิ่งนี้
ต้องการความช่วยเหลือ?
พบปัญหากับเครื่องมือนี้หรือไม่? แจ้งทีมงานของเรา
รายงานปัญหา

เพิ่มเครื่องมือฟรีนี้ลงในเว็บไซต์ของคุณเอง — คัดลอกและวางโค้ดด้านล่าง