-v : 요청과 응답을 상세하게 로그로 찍는다.$HOME/.curlrc 파일에 기본 옵션들을 지정해 둘 수 있다.-o [FILENAME] 응답 결과를 파일로 저장한다.-s/--silent : 본문 외의 다른 메시지는 찍지 말 것.-L : redirect 따라가기-f/--fail : fail silently-S : -s와 함께 사용시, 에러 발생시 에러보여주기curl -fsSL "<url>"
curl --user name:password http://www.example.com
name:password 에 특수 문자가 들어갈 경우 홑따옴표로 감싸면 된다.
-X GET|POST|PUT|HEAD|… 로 메소드를 지정할 수 있다.
-F--data-binary
-D, --dump-header <file> 으로 헤더를 덤프할 수 있다. <file>을 -로 지정하면 스트림으로 출력한다.
-H “HeaderKey: HeaderValue” 혹은 --header “HeaderKey: HeaderValue” 형태로 요청 헤더를 지정할 수 있다.
200 이 아닌 경우 shell script를 실패하게 하려면 -s -w “%{http_code}”를 사용한다.response=$(curl -s -w "%{http_code}" -o /path/to/download.zip http://url.to/target.zip)
if [ "$response" != "200" ]
then
exit 1
fi
curl --user myusername:mypassword http://...
7.82 버전부터 --json 옵션 생김# --json 은 아래와 동일한 옵션이다. --data [arg] --header "Content-Type: application/json" --header "Accept: application/json"
# 기본 사용법
curl --json '{"tool": "curl"}' https://example.com/
# json 파일 지정
curl --json @json.txt https://example.com/
# stdin
echo '{"a":"b"}' | curl --json @- https://example.com/
jo name=daniel tool=curl | curl --json @- https://httpbin.org/post | jq
--connect-timeout 3.14 : connection timeout 초. fractional--max-time 2.92 : 전송 시간 제한 초. fractional. 아마도 read-timeout 같은 역할인듯보임.--max-time 10 : 각 retry 가 기다릴 시간 초.--retry 5 : 재시도 횟수 최대 5회--retry-delay 3 : 재시도 마다 주어질 delay 초갑자기 아래와 같은 오류가 발생했는데, 이는 curl이나 운영체제의 문제가 아니라 당시 접속하고 있던 해당 WiFi 망의 라위터가 인증서를 조작한 것으로 보인다.
OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
혹은 http_proxy, https_proxy 같은 환경 변수 설정의 proxy 서버에서 인증서를 변조할 수도 있다.
이로인해, curl 뿐만 아니라 웹 브라우저에서도 올바로 접속이 안됐다.
망이나 프록시 서버를 바꿔서 접속하니까 잘 됐다.