티스토리 뷰

728x90
반응형

https://curl.se/download.html

매번 까먹는 curl 사용법 정리 해봅니다... 일명 curl cheatsheet

 

# GET data 전송법
curl http://127.0.0.1/?key=value&key2=value2
curl -G http://127.0.0.1/ -d key=value -d key2=value2

# POST data 전송법
curl http://127.0.0.1/ -d key=value -d key2=value2
curl http://127.0.0.1/ -d "key=value&key2=value2"
curl -X POST -d "key=value" http://127.0.0.1/

# JSON data 전송법
curl -X POST -H "Content-Type: application/json" -d '{"key": number, "key2": "string"}' http://127.0.0.1/
curl -X POST -H "Content-Type: application/json" -d "{\"key\": number, \"key2\": \"string\"}" http://127.0.0.1/

# Cookie 값 지정법
curl http://127.0.0.1/ -b "session=domdomi"

# 파일 업로드
curl http://127.0.0.1/ -d "@/etc/passwd"
curl http://127.0.0.1/ -F pwdfile=@/etc/passwd -F hello=domdomi

# curl 결과 저장
curl http://127.0.0.1/ > test.txt
curl http://127.0.0.1/ -o test.txt
curl -O http://127.0.0.1/test.txt # -O 옵션은 파일 이름 그대로 다운
curl -O http://127.0.0.1/foo[0-9].txt # foo0.txt 부터 foo9.txt 파일 다운 받기
curl -O http://127.0.0.1/foo-[a-z][0-9].txt # foo-a0 ~ foo-z9 다운 받기
curl -O http://127.0.0.1/{foo,bar,baz}.txt # foo.txt, bar.txt, baz.txt 다운 받기

# Linux 명령어와 연계
curl http://127.0.0.1/ -d whoami=`whoami|base64`
cat /etc/passwd | base64 | curl http://127.0.0.1/ -d @- # 명령실행 결과를 base64 인코딩해서 전송

 

아래는 그냥 help 한 결과!

$ 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".

 

우선 이렇게 적어두고 나중에 또 쓸모 있고 자주 쓰일 것 같은 거 있으면 추가할 예정!

 

- 끝 -

728x90
반응형
댓글