기타

curl 주요 옵션 정리

ipxy 2025. 4. 3. 16:18
728x90

 

🧾 curl 주요 옵션 정리

📡 1. 기본 요청

curl http://example.com
  • 기본 GET 요청을 보냄

🔁 2. HTTP 메서드 지정

curl -X POST http://example.com
curl -X PUT http://example.com
  • -X를 이용해 HTTP 메서드 설정

📤 3. 데이터 전송 (POST/PUT 등)

curl -d "key=value&key2=value2" http://example.com
curl -d '{"json":"data"}' -H "Content-Type: application/json" http://example.com
  • -d: 데이터 전송
  • -H: 헤더 설정

🧾 4. 헤더 추가

curl -H "Authorization: Bearer token" http://example.com
curl -H "Content-Type: application/json" http://example.com

💾 5. 응답 저장

curl -o output.txt http://example.com
  • -o: 응답을 파일로 저장

⏱️ 6. 타임아웃 설정

curl --connect-timeout 3 --max-time 5 http://example.com
  • --connect-timeout: 연결 시도 최대 시간 (초)
  • --max-time: 전체 요청/응답 최대 시간 (초)

🔒 7. HTTPS 인증서 무시 (테스트용)

curl -k https://example.com
  • -k 또는 --insecure: 인증서 검증 생략 (위험, 테스트용)

📂 8. 파일 업로드 (멀티파트)

curl -F "file=@/path/to/file.txt" http://example.com/upload
  • -F: 멀티파트 form 데이터 전송

📥 9. 리디렉션 자동 추적

curl -L http://example.com
  • -L: 3xx 리디렉션 자동 따라감

🧪 10. 응답 코드 확인

curl -s -o /dev/null -w "%{http_code}" http://example.com
  • -s: silent 모드 (진행률 등 숨김)
  • -o /dev/null: 응답 내용 버림
  • -w "%{http_code}": HTTP 상태 코드만 출력

 

728x90