개요
curl은 웹 어플리케이션에 HTTP요청을 보낼 수 있는 커맨드라인 툴이다. 웹 어플리케이션 동작확인에 자주 쓰인다.
자주 사용하는 curl 옵션을 정리해둔다.
옵션 목록
$curl --help
Usage: curl [options...] <url>
-d, --data <data> HTTP POST data
-f, --fail Fail fast with no output on HTTP errors
-h, --help <category> Get help for commands
-i, --include Include protocol response headers in the output
-o, --output <file> Write to file instead of stdout
-O, --remote-name Write output to a file named as the remote file
-s, --silent Silent mode
-T, --upload-file <file> Transfer local FILE to destination
-u, --user <user:password> Server user and password
-A, --user-agent <name> Send User-Agent <name> to server
-v, --verbose Make the operation more talkative
-V, --version Show version number and quit
This is not the full help, this menu is stripped into categories.
Use "--help category" to get an overview of all categories.
For all options use the manual or "--help all".
Basic 인증 추가
Basic인증 추가는 -u
옵션을 사용한다.
예)
curl -u user_01:password01 "http://example.com"
프록시 설정
프록시를 설정하고 싶으면 x 옵션을 사용한다.
-x, --proxy [protocol://]host[:port]
예)
curl -x http://localhost:8080
셸 변수와 연동하기
셸 변수를 적용시키고 싶으면 쌍따옴표로 환경변수를 감싸면 된다. 주로 POST 요청을 보낼 때 –data-binary 옵션과 함께 사용하는 경우가 많다.
예)
curl --data-binary "$SHELL_VAL"
파라메터 부분이 JSON과 같은 포맷이라면 다음과 같은 방식으로 사용할 수도 있다.
curl --data-binary '{"SHELL_VAL": "'"$SHELL_VAL"'" }'
리다이렉트 따라가기
서버가 회신하는 리다이렉트를 따라가고 싶으면 -L
옵션을 사용한다.
타임아웃 설정
타임아웃은 --max-time
으로 설정한다.
ex) 타임아웃 10초 설정
curl --max-time 10
서버의 TLS증명서 검증 패스
curl은 기본적으로 서버의 TLS증명서를 검증하도록 되어 있다.
서버에 독자적으로 구축한 TLS 증명서를 사용하는 경우는 이 검증을 통과하지 못하므로, 이 검증 기능을 꺼두고 싶을 때도 있다. 그럴떄는 -k
옵션을 사용한다.