홈/엔지니어/네트워킹 / 서버/curl · wget 실전 가이드 — API 테스트…
네트워킹 / 서버초급UbuntuDebianCentOSmacOScurlwgetapi

curl · wget 실전 가이드 — API 테스트와 파일 다운로드

curl로 REST API를 테스트하고 헤더·인증·바디를 다루는 방법, wget으로 파일을 다운로드하고 미러링하는 방법, 두 도구의 차이점을 정리합니다.

목차
  1. curl 기본
  2. HTTP 메서드와 헤더
  3. 인증
  4. 파일 업로드
  5. 파일 다운로드
  6. wget 기본
  7. curl vs wget 선택 기준

curl 기본

Bash
# GET 요청
curl https://api.example.com/users

# 응답 예쁘게 출력 (jq 조합)
curl -s https://api.github.com/users/octocat | jq '.'

# 상태 코드만 확인
curl -o /dev/null -s -w "%{http_code}" https://example.com

# 상세 정보 (헤더 포함)
curl -v https://example.com

# 헤더만 출력
curl -I https://example.com

# 리다이렉트 따라가기
curl -L https://example.com

# 타임아웃 설정
curl --connect-timeout 5 --max-time 30 https://example.com

HTTP 메서드와 헤더

Bash
# POST — JSON 바디
curl -X POST https://api.example.com/users   -H "Content-Type: application/json"   -d '{"name":"Alice","email":"alice@example.com"}'

# PUT
curl -X PUT https://api.example.com/users/1   -H "Content-Type: application/json"   -d '{"name":"Alice Updated"}'

# DELETE
curl -X DELETE https://api.example.com/users/1

# PATCH
curl -X PATCH https://api.example.com/users/1   -H "Content-Type: application/json"   -d '{"email":"new@example.com"}'

# 여러 헤더
curl https://api.example.com   -H "Accept: application/json"   -H "X-Request-ID: abc123"   -H "User-Agent: MyScript/1.0"

인증

Bash
# Bearer 토큰
curl -H "Authorization: Bearer eyJhbGci..." https://api.example.com/me

# Basic Auth
curl -u username:password https://api.example.com
# 또는
curl -H "Authorization: Basic $(echo -n user:pass | base64)" https://api.example.com

# API 키
curl -H "X-API-Key: your-api-key" https://api.example.com

# 쿠키
curl -b "session=abc123; token=xyz" https://example.com

# 쿠키 저장 및 전송
curl -c cookies.txt https://example.com/login -d "user=admin&pass=1234"
curl -b cookies.txt https://example.com/dashboard

파일 업로드

Bash
# 폼 파일 업로드 (multipart)
curl -F "file=@/path/to/file.pdf" https://api.example.com/upload
curl -F "file=@image.jpg;type=image/jpeg" -F "name=profile" https://example.com

# 바이너리 데이터 직접
curl -X PUT --data-binary @file.tar.gz https://example.com/upload

파일 다운로드

Bash
# 파일 저장 (-O: 원본 파일명, -o: 지정 파일명)
curl -O https://example.com/file.tar.gz
curl -o myfile.tar.gz https://example.com/file.tar.gz

# 진행률 표시
curl -# -O https://example.com/large-file.iso

# 이어받기 (중단된 다운로드)
curl -C - -O https://example.com/large-file.iso

# 병렬 다운로드 (xargs 조합)
cat urls.txt | xargs -n1 -P4 curl -O

wget 기본

Bash
# 파일 다운로드
wget https://example.com/file.tar.gz

# 이어받기
wget -c https://example.com/large-file.iso

# 조용히 (진행률 없이)
wget -q https://example.com/file.tar.gz

# 재시도 횟수
wget --tries=5 https://example.com/file.tar.gz

# 특정 파일명으로 저장
wget -O myfile.tar.gz https://example.com/file

# 재귀 다운로드 (사이트 미러링)
wget -r -np -nH --cut-dirs=1 https://example.com/docs/

# 특정 파일 형식만
wget -r -A "*.pdf" https://example.com/papers/

curl vs wget 선택 기준

상황추천
REST API 테스트curl
HTTP 메서드/헤더 커스텀curl
파일 다운로드 (이어받기)wget
사이트 미러링wget
스크립트 내 API 호출curl
FTP 파일 다운로드curl
#curl#wget#api#http#파일다운로드#네트워크
편집 안내 · Editorial Note

AI 도구가 초안 작성에 사용될 수 있습니다. 명령어의 실행 여부와 검증 환경은 각 가이드에 기재된 근거를 확인하세요. 적용 전 사용 중인 버전의 공식 문서를 확인하고, 오류는 이메일로 알려주세요. 이메일로 제보

질문 & 답변 (Q&A)

이 가이드에 대해 궁금한 점을 질문해보세요. 확인 후 답변드립니다.