레이블이 wget인 게시물을 표시합니다. 모든 게시물 표시
레이블이 wget인 게시물을 표시합니다. 모든 게시물 표시

curl 유용한 옵션

# wget
# 예전에는 웹에 올라온 파일을 콘솔환경에서 다운받을때 wget 명령어를 주로 사용했다.
# 다음과 같이 다운받을 대상 url 만 명시하면 파일이 다운로드되는 형식이다.
wget http://ysoftman.com/ysoftman.tar.gz

# ysoftman.out 파일로 내용 저장
wget -O ysoftman.out http://ysoftman.com/ysoftman.html

# -O 뒤 - 주면 stdout 으로 다운받은 내용을 강제 출력한다.
wget -O - http://ysoftman.com/ysoftman.html

# curl
# 언제부터인가 wget 대신 curl 을 많이 사용하게 된다.
# 보통 curl 특정 특정 웹의 html 응답을 파악할때 사용한다.
curl http://www.google.com

# curl 로 파일을 받을때는 -O (대문자 o) 옵션을 주면 된다.
curl -O http://ysoftman.com/ysoftman.tar.gz

# -o 로 파일을 명시할 수 도 있다.
# -o- 로 -를 주면 stdout 으로 다운받은 내용을 강제 출력한다.
curl -o ysoftman.out http://ysoftman.com/ysoftman.tar.gz

# 만약 다운받은 파일이 예상했던 크기보다 작다면 -v 옵션으로 다운로드 과정을 살펴보자.
curl -Ov http://ysoftman.com/ysoftman.tar.gz

# HTTP/1.1 302 (redirect) 로 해당 파일을 redirect 하여 다운로드를 받아야한다면
# -L 옵션으로 redirect 를 따라가서 파일을 다운로드 받을 수 있다.
# 참고로 wget 은 별도의 옵션없이 redirect 처리가 된다.
curl -OLv http://ysoftman.com/ysoftman.tar.gz

# POST 방식으로 data 를 요청할때
# -X POST 방식(-d 가 있으면 생략가능)
# -d 데이터, 파일을 사용할때는 @파일명
# --trace-ascii /dev/stdout 표준 출력을 트레이스하여 데이터 내용을 확인할 수 있다.
curl -v -X POST http://ysoftman.com -d "ysoftman" --trace-ascii /dev/stdout

# 파일 업로드
# -F 멀티파트 폼데이터로 파일 전송
# zzz : form 필드에서 aaa.txt 데이터가 들어갈 위치(키)
# @전송할 파일명,
curl -X POST -F 'zzz=@./aaa.txt' http://ysoftman.com/upload

# -s, --silent 진행상태 에러메시지등 표시하지 않기
curl -s http://www.google.co.kr

# -i --include 헤더와 바디 보기
curl -i http://www.google.co.kr

# -I, --head 헤더만 보기
curl -I http://www.google.co.kr

# -I 는 기본적으로 HEAD 커맨드를 사용한다.
# GET 요청시에서의 헤더만 보기
curl -I -X GET http://www.google.co.kr

# -L 302 redirect 하여 응답헤더 보기
curl -IL http://www.google.com

# -D filename 헤더 덤프해서 보기(- 로 파일명을 안줄 수 있다)
curl -D - http://www.google.co.kr

# -H, --header 요청헤더 설정(헤더는 대소문자 구분하지 않는다.)
curl -I -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36' -H 'Accept-Encoding: br' https://www.google.co.kr

# 응답 데이터 크기만 보기
curl -s http://www.google.co.kr -w '%{size_download}\n' -o /dev/null

# 응답 상태 코드만 보기
curl -s http://www.google.co.kr -w '%{http_code}\n' -o /dev/null

# elapsed(경과시간) 측정
curl http://www.google.co.kr -w "\n\nConnect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total}"

# https + http2 요청
curl -sI http://www.google.co.kr --http2

# https + http1.1 요청
curl -sI http://www.google.co.kr --http1.1