개요

- curl은 command line 용 data transfer tool 이다.

- http/https/ftp/ldap/scp/telnet/smtp/pop3 등 주요 프로토콜 지원.

사용법

구분 명령어
기본 $ curl http://example.com?test=1
Method 지정 $ curl -X GET/POST/DELETE/PUT http://example.com?test=1
Request Header 지정 $ curl -H "Content-Type: text/xml" 
Request Body 지정(JSON) $ curl -X PUT -H "Content-Type: application/json; charset=utf-8" -d '{"message":"hello"}' http://127.0.0.1:3000/api/chat
Request Body 지정(FORM) $ curl -X PUT -H "application/x-www-form-urlencoded" -d '{"message":"hello"}' http://127.0.0.1:3000/api/chat
- Response Header/Body 가져오기 $ curl -i http://example.com?test=1
- Response Body만 가져오기 $ curl -l http://example.com?test=1
응답시간 확인

$ curl -o /dev/null -s  -w %{time_total}\\n http://example.com

time_namelookup: %{time_namelookup}\n

time_connect: %{time_connect}\n

time_appconnect: %{time_appconnect}\n

time_pretransfer: %{time_pretransfer}\n

time_redirect: %{time_redirect}\n

time_starttransfer: %{time_starttransfer}\n

응답코드 확인

$ curl -o /dev/null -w %{http_code}% http://example.com

기타

-s : 프로그레스나 에러 정보를 보여주지 않는다.

-o : 응답을 stdout이 아닌 file로 출력한다.

 

'서버 > linux' 카테고리의 다른 글

CentOS 7 설치하기  (0) 2020.09.02
[Linux] 사용자 계정 관리  (0) 2020.06.10
쉘 스크립트  (0) 2020.01.18
shell script  (0) 2019.11.15

+ Recent posts