Tài liệu tham khảo curl có thể tìm kiếm và in được — phương thức HTTP, header, dữ liệu và form, auth, tải xuống, cookie, TLS, proxy và gỡ lỗi. Miễn phí.

Cơ bản

12
curl https://api.example.com
Gửi request GET và in phần thân
curl -o page.html https://example.com
Lưu phản hồi vào file có tên
curl -O https://example.com/file.zip
Lưu dùng tên file từ xa
curl -i https://example.com
Hiển thị header phản hồi kèm phần thân
curl -I https://example.com
Chỉ lấy header phản hồi (HEAD)
curl -v https://example.com
Đầu ra chi tiết của request/response
curl -s https://example.com
Chế độ im lặng, ẩn tiến trình và lỗi
curl -sS https://example.com
Im lặng nhưng vẫn hiện lỗi
curl -L https://example.com
Theo chuyển hướng HTTP (3xx)
curl https://a.com https://b.com
Request nhiều URL trong một lệnh
curl 'https://x.com/p?[1-5]'
Dùng khoảng số để lặp URL
curl --version
In phiên bản và tính năng của curl

Phương thức HTTP

9
curl -X GET https://api.example.com
Gửi request GET một cách rõ ràng
curl -X POST https://api.example.com
Gửi request POST
curl -X PUT https://api.example.com/1
Gửi request PUT để thay thế tài nguyên
curl -X PATCH https://api.example.com/1
Gửi request PATCH để cập nhật trường
curl -X DELETE https://api.example.com/1
Gửi request DELETE
curl -I https://api.example.com
Gửi request HEAD chỉ lấy header
curl -X OPTIONS https://api.example.com
Gửi request preflight OPTIONS
curl --head https://api.example.com
Dạng đầy đủ của -I cho request HEAD
curl --request POST https://x.com
Dạng đầy đủ của -X để đặt phương thức

Header

10
curl -H 'Accept: application/json' https://x.com
Thêm một header request
curl -H 'X-Token: abc' -H 'X-Env: dev' https://x.com
Thêm nhiều header
curl -H 'Content-Type: application/json' https://x.com
Khai báo content type của thân request
curl -H 'Authorization: Bearer TOKEN' https://x.com
Gửi header authorization dạng bearer
curl -H 'Host: example.com' https://1.2.3.4
Ghi đè header Host
curl -H 'Accept-Encoding: gzip' https://x.com
Yêu cầu phản hồi nén gzip
curl -A 'MyAgent/1.0' https://x.com
Đặt chuỗi User-Agent
curl -e 'https://ref.com' https://x.com
Đặt header Referer
curl -H 'X-Debug:' https://x.com
Bỏ header mặc định bằng cách để trống
curl --compressed https://x.com
Yêu cầu và tự giải nén phản hồi

Gửi dữ liệu

11
curl -d 'name=Jane&age=30' https://x.com
POST dữ liệu form mã hóa URL
curl -d '@payload.json' https://x.com
POST dữ liệu đọc từ file
curl --data-urlencode 'q=hello world' https://x.com
POST một trường mã hóa URL
curl --data-binary '@file.bin' https://x.com
POST byte thô không xử lý
curl -G --data-urlencode 'q=cats' https://x.com
Nối dữ liệu dạng query string GET
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Jane"}' https://x.com
POST một thân JSON
curl --json '{"name":"Jane"}' https://x.com
POST JSON và tự đặt header JSON
curl -F 'name=Jane' https://x.com
Gửi một trường form multipart
curl -F 'file=@photo.png' https://x.com
Tải lên file dạng form-data multipart
curl -F 'file=@a.pdf;type=application/pdf' https://x.com
Tải lên file với MIME type rõ ràng
curl -d '' https://x.com
POST với thân rỗng

Xác thực

9
curl -u user:pass https://x.com
Xác thực HTTP basic
curl -u user https://x.com
Basic auth, hỏi mật khẩu
curl -H 'Authorization: Bearer TOKEN' https://x.com
Gửi header bearer token
curl --oauth2-bearer TOKEN https://x.com
Gửi bearer token OAuth 2.0
curl --digest -u user:pass https://x.com
Dùng xác thực HTTP digest
curl --ntlm -u user:pass https://x.com
Dùng xác thực NTLM
curl --netrc https://x.com
Đọc thông tin đăng nhập từ ~/.netrc
curl --netrc-file creds https://x.com
Đọc thông tin đăng nhập từ file netrc tùy chỉnh
curl -H 'X-Api-Key: KEY' https://x.com
Gửi header API key

Tải xuống & tải lên

11
curl -O https://x.com/file.zip
Tải xuống dùng tên file từ xa
curl -o out.zip https://x.com/file.zip
Tải xuống vào tên file đã chọn
curl -OL https://x.com/file.zip
Tải xuống và theo chuyển hướng
curl -C - -O https://x.com/file.zip
Tiếp tục một lượt tải dở dang
curl --limit-rate 200k -O https://x.com/f
Giới hạn tốc độ truyền
curl -r 0-1023 -o part https://x.com/f
Chỉ tải xuống một khoảng byte
curl --retry 3 -O https://x.com/f
Thử lại tải xuống khi thất bại
curl -T file.txt ftp://x.com/
Tải lên file bằng PUT/FTP
curl -T file.txt https://x.com/up
Tải lên file qua HTTP PUT
curl --create-dirs -o a/b/f.txt https://x.com
Tạo thư mục còn thiếu cho đầu ra
curl -# -O https://x.com/file.zip
Hiển thị thanh tiến trình đơn giản

Cookie

8
curl -b 'session=abc123' https://x.com
Gửi một cookie nội tuyến
curl -b cookies.txt https://x.com
Gửi cookie từ một file
curl -c cookies.txt https://x.com
Ghi cookie nhận được vào jar
curl -b jar.txt -c jar.txt https://x.com
Đọc và cập nhật cùng một cookie jar
curl -b 'a=1; b=2' https://x.com
Gửi nhiều cookie cùng lúc
curl -c - https://x.com
In cookie nhận được ra stdout
curl --junk-session-cookies -b jar.txt https://x.com
Bỏ qua cookie phiên từ jar
curl -L -c jar.txt -b jar.txt https://x.com/login
Giữ phiên qua các lần chuyển hướng

TLS / SSL

10
curl -k https://x.com
Cho phép không an toàn (bỏ xác minh chứng chỉ)
curl --cacert ca.pem https://x.com
Xác minh bằng bộ CA tùy chỉnh
curl --capath /etc/ssl/certs https://x.com
Dùng một thư mục chứng chỉ CA
curl --cert client.pem https://x.com
Gửi chứng chỉ client
curl --cert client.pem --key client.key https://x.com
Dùng chứng chỉ client và khóa riêng
curl --tlsv1.2 https://x.com
Yêu cầu tối thiểu TLS 1.2
curl --tlsv1.3 https://x.com
Yêu cầu tối thiểu TLS 1.3
curl --tls-max 1.2 https://x.com
Giới hạn phiên bản TLS tối đa
curl --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://x.com
Hạn chế các cipher TLS cho phép
curl -vI https://x.com
Kiểm tra chi tiết bắt tay TLS

Proxy

9
curl -x http://proxy:8080 https://x.com
Định tuyến request qua proxy HTTP
curl --proxy http://proxy:8080 https://x.com
Dạng đầy đủ của -x để đặt proxy
curl -x proxy:8080 -U user:pass https://x.com
Xác thực với proxy
curl --proxy-user user:pass -x proxy:8080 https://x.com
Dạng đầy đủ của thông tin đăng nhập proxy
curl --socks5 127.0.0.1:1080 https://x.com
Dùng proxy SOCKS5
curl --socks5-hostname 127.0.0.1:1080 https://x.com
Proxy SOCKS5 với phân giải DNS từ xa
curl --socks4 127.0.0.1:1080 https://x.com
Dùng proxy SOCKS4
curl --noproxy example.com https://x.com
Bỏ qua proxy cho các host cho trước
curl -x '' https://x.com
Tắt mọi proxy đã cấu hình

Gỡ lỗi & đầu ra

11
curl -w '%{http_code}\n' -o /dev/null -s https://x.com
Chỉ in mã trạng thái HTTP
curl -w '%{time_total}\n' -o /dev/null -s https://x.com
In tổng thời gian truyền
curl -w '@format.txt' https://x.com
Đọc định dạng write-out từ một file
curl -D headers.txt https://x.com
Xuất header phản hồi ra một file
curl -D - -o body.txt https://x.com
Header ra stdout, thân ra một file
curl --trace trace.txt https://x.com
Trace hex đầy đủ của lượt truyền
curl --trace-ascii - https://x.com
Trace ASCII ra stdout
curl --trace-time -v https://x.com
Thêm dấu thời gian vào đầu ra chi tiết
curl -v https://x.com 2>&1 | less
Phân trang qua log chi tiết
curl -sS -o /dev/null -w '%{size_download}\n' https://x.com
In số byte đã tải xuống
curl --libcurl out.c https://x.com
Xuất mã nguồn C libcurl tương đương

Timeout & thử lại

10
curl --connect-timeout 5 https://x.com
Giới hạn giai đoạn kết nối theo giây
curl --max-time 30 https://x.com
Giới hạn toàn bộ thời gian thao tác
curl --retry 3 https://x.com
Thử lại khi gặp lỗi tạm thời
curl --retry 3 --retry-delay 2 https://x.com
Chờ giữa các lần thử lại
curl --retry 5 --retry-max-time 60 https://x.com
Giới hạn tổng thời gian thử lại
curl --retry-connrefused https://x.com
Cũng thử lại khi bị từ chối kết nối
curl --retry-all-errors https://x.com
Thử lại với mọi lỗi, không chỉ tạm thời
curl --speed-limit 100 --speed-time 10 https://x.com
Hủy nếu quá chậm trong một khoảng thời gian
curl --keepalive-time 60 https://x.com
Đặt khoảng thời gian TCP keep-alive
curl --expect100-timeout 1 https://x.com
Giới hạn thời gian chờ 100-continue

Không có mục nào khớp với “:q”.


Cần trợ giúp?
Gặp sự cố với công cụ này? Hãy cho đội ngũ của chúng tôi biết.
Báo cáo sự cố

Thêm công cụ miễn phí này vào trang web của riêng bạn — sao chép và dán mã bên dưới.