cURL is a communication tool using various protocols.
cURL은 다양한 프로토콜을 지원하는 통신용 툴.
* Supported: DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP.
1. Feature 특징
❑ Even with minimal installation of the operating system, it is installed.
최소한으로 운영체제를 설치해도 함께 설치됨.
최소한으로 운영체제를 설치해도 함께 설치됨.
❑ Various references on the Internet.
인터넷에 존재하는 다양한 레퍼런스.
인터넷에 존재하는 다양한 레퍼런스.
2. How to install 설치 방법
: No need to install. 설치 불필요.
❑ GET method - defalt
GET 메소드 - 일반
GET 메소드 - 일반
$ curl -v --get http://ifconfig.me
* Trying 216.239.36.21:80...
* TCP_NODELAY set
* Connected to ifconfig.me (216.239.36.21) port 80 (#0)
> GET / HTTP/1.1
> Host: ifconfig.me
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 16 Jul 2020 13:45:23 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 13
< Access-Control-Allow-Origin: *
< Via: 1.1 google
<
* Connection #0 to host ifconfig.me left intact
12.xxx.xxx.xxx
* Trying 216.239.36.21:80...
* TCP_NODELAY set
* Connected to ifconfig.me (216.239.36.21) port 80 (#0)
> GET / HTTP/1.1
> Host: ifconfig.me
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 16 Jul 2020 13:45:23 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 13
< Access-Control-Allow-Origin: *
< Via: 1.1 google
<
* Connection #0 to host ifconfig.me left intact
12.xxx.xxx.xxx
$
$ curl -i --get http://ifconfig.me
HTTP/1.1 200 OK
Date: Thu, 16 Jul 2020 13:45:44 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 13
Access-Control-Allow-Origin: *
Via: 1.1 google
12.xxx.xxx.xxx
HTTP/1.1 200 OK
Date: Thu, 16 Jul 2020 13:45:44 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 13
Access-Control-Allow-Origin: *
Via: 1.1 google
12.xxx.xxx.xxx
-i: Include header.
헤더 포함.
-v: Include detailed description(verbose).
세부 사항 포함.
❑ GET method - parameter
GET 메소드 - 파라미터
GET 메소드 - 파라미터
$ curl -v --get --data-urlencode "bb=12345<>#" http://ifconfig.me
* Trying 216.239.34.21:80...
* TCP_NODELAY set
* Connected to ifconfig.me (216.239.34.21) port 80 (#0)
> GET /?bb=12345%3C%3E%23 HTTP/1.1
> Host: ifconfig.me
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 16 Jul 2020 16:06:18 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 13
< Access-Control-Allow-Origin: *
< Via: 1.1 google
<
* Connection #0 to host ifconfig.me left intact
* Trying 216.239.34.21:80...
* TCP_NODELAY set
* Connected to ifconfig.me (216.239.34.21) port 80 (#0)
> GET /?bb=12345%3C%3E%23 HTTP/1.1
> Host: ifconfig.me
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Thu, 16 Jul 2020 16:06:18 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 13
< Access-Control-Allow-Origin: *
< Via: 1.1 google
<
* Connection #0 to host ifconfig.me left intact
12.xxx.xxx.xxx
--data-urlencode: Transfer parameters using URL encoding.
URL 인코딩을 사용하여 파라미터 전송.
❑ POST method - default
POST 메소드 - 일반
POST 메소드 - 일반
$ curl -X POST --data-urlencode "param1=1<>#" --trace-ascii /dev/stdout http://ifconfig.me
Note: Unnecessary use of -X or --request, POST is already inferred.
== Info: Trying 216.239.32.21:80...
== Info: TCP_NODELAY set
== Info: Connected to ifconfig.me (216.239.32.21) port 80 (#0)
=> Send header, 145 bytes (0x91)
0000: POST / HTTP/1.1
0011: Host: ifconfig.me
0024: User-Agent: curl/7.68.0
003d: Accept: */*
004a: Content-Length: 17
005e: Content-Type: application/x-www-form-urlencoded
008f:
=> Send data, 17 bytes (0x11)
0000: param1=1%3C%3E%23
== Info: upload completely sent off: 17 out of 17 bytes
== Info: Mark bundle as not supporting multiuse
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Thu, 16 Jul 2020 17:01:14 GMT
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 235
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 32 bytes (0x20)
0000: Access-Control-Allow-Origin: *
<= Recv header, 67 bytes (0x43)
0000: Set-Cookie: flash=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GM
0040: T
<= Recv header, 33 bytes (0x21)
0000: X-Content-Type-Options: nosniff
<= Recv header, 17 bytes (0x11)
0000: Via: 1.1 google
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 16 Jul 2020 17:01:14 GMT
<= Recv header, 24 bytes (0x18)
0000: Cache-Control: private
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 235 bytes (0xeb)
0000: {. "ip": "xxx",. "city": "xxx",. "region": "xxx
0040: ",. "country": "xxx",. "loc": "xxx",. "org": "xxx
0080: xxx",. "postal": "xxx",. "timezone": "xxx",.
00c0: "readme": "https://ipinfo.io/missingauth".}
{
"ip": "xxx",
"city": "xxx",
"region": "xxx",
"country": "xxx",
"loc": "xxx",
"org": "xxx",
"postal": "xxx",
"timezone": "xxx",
"readme": "https://ipinfo.io/missingauth"
== Info: Connection #0 to host ifconfig.me left intact
Note: Unnecessary use of -X or --request, POST is already inferred.
== Info: Trying 216.239.32.21:80...
== Info: TCP_NODELAY set
== Info: Connected to ifconfig.me (216.239.32.21) port 80 (#0)
=> Send header, 145 bytes (0x91)
0000: POST / HTTP/1.1
0011: Host: ifconfig.me
0024: User-Agent: curl/7.68.0
003d: Accept: */*
004a: Content-Length: 17
005e: Content-Type: application/x-www-form-urlencoded
008f:
=> Send data, 17 bytes (0x11)
0000: param1=1%3C%3E%23
== Info: upload completely sent off: 17 out of 17 bytes
== Info: Mark bundle as not supporting multiuse
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Thu, 16 Jul 2020 17:01:14 GMT
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 235
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 32 bytes (0x20)
0000: Access-Control-Allow-Origin: *
<= Recv header, 67 bytes (0x43)
0000: Set-Cookie: flash=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GM
0040: T
<= Recv header, 33 bytes (0x21)
0000: X-Content-Type-Options: nosniff
<= Recv header, 17 bytes (0x11)
0000: Via: 1.1 google
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 16 Jul 2020 17:01:14 GMT
<= Recv header, 24 bytes (0x18)
0000: Cache-Control: private
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 235 bytes (0xeb)
0000: {. "ip": "xxx",. "city": "xxx",. "region": "xxx
0040: ",. "country": "xxx",. "loc": "xxx",. "org": "xxx
0080: xxx",. "postal": "xxx",. "timezone": "xxx",.
00c0: "readme": "https://ipinfo.io/missingauth".}
{
"ip": "xxx",
"city": "xxx",
"region": "xxx",
"country": "xxx",
"loc": "xxx",
"org": "xxx",
"postal": "xxx",
"timezone": "xxx",
"readme": "https://ipinfo.io/missingauth"
== Info: Connection #0 to host ifconfig.me left intact
헤더 포함.
--trace-ascii /dev/stdout: Print sending/receiving contents to the standard output device. This can identify the body.
표준 출력 장치로 송수신 내용을 출력. 이렇게 하면 바디를 확인할 수 있다.
❑ POST method - JSON
POST 메소드 - JSON
POST 메소드 - JSON
$ curl -X POST -d '{"param1":1, "param2":2}' -H "Content-Type: application/json" --trace-ascii /dev/stdout http://ifconfig.me
Note: Unnecessary use of -X or --request, POST is already inferred.
== Info: Trying 216.239.38.21:80...
== Info: TCP_NODELAY set
== Info: Connected to ifconfig.me (216.239.38.21) port 80 (#0)
=> Send header, 128 bytes (0x80)
0000: POST / HTTP/1.1
0011: Host: ifconfig.me
0024: User-Agent: curl/7.68.0
003d: Accept: */*
004a: Content-Type: application/json
006a: Content-Length: 24
007e:
=> Send data, 24 bytes (0x18)
0000: {"param1":1, "param2":2}
== Info: upload completely sent off: 24 out of 24 bytes
== Info: Mark bundle as not supporting multiuse
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Thu, 16 Jul 2020 16:57:27 GMT
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 235
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 32 bytes (0x20)
0000: Access-Control-Allow-Origin: *
<= Recv header, 67 bytes (0x43)
0000: Set-Cookie: flash=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GM
0040: T
<= Recv header, 33 bytes (0x21)
0000: X-Content-Type-Options: nosniff
<= Recv header, 17 bytes (0x11)
0000: Via: 1.1 google
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 16 Jul 2020 16:57:27 GMT
<= Recv header, 24 bytes (0x18)
0000: Cache-Control: private
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 235 bytes (0xeb)
0000: {. "ip": "12.xxx.xxx.xxx",. "city": "Seoul",. "region": "xxx
0040: ",. "country": "xxx",. "loc": "xxx",. "org": "xxx
0080: xxx",. "postal": "xxx",. "timezone": "xxx",.
00c0: "readme": "https://ipinfo.io/missingauth".}
{
"ip": "12.xxx.xxx.xxx",
"city": "xxx",
"region": "xxx",
"country": "xxx",
"loc": "37xxx",
"org": "xxx",
"postal": "xxx",
"timezone": "xxx",
"readme": "https://ipinfo.io/missingauth"
== Info: Connection #0 to host ifconfig.me left intact
Note: Unnecessary use of -X or --request, POST is already inferred.
== Info: Trying 216.239.38.21:80...
== Info: TCP_NODELAY set
== Info: Connected to ifconfig.me (216.239.38.21) port 80 (#0)
=> Send header, 128 bytes (0x80)
0000: POST / HTTP/1.1
0011: Host: ifconfig.me
0024: User-Agent: curl/7.68.0
003d: Accept: */*
004a: Content-Type: application/json
006a: Content-Length: 24
007e:
=> Send data, 24 bytes (0x18)
0000: {"param1":1, "param2":2}
== Info: upload completely sent off: 24 out of 24 bytes
== Info: Mark bundle as not supporting multiuse
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Thu, 16 Jul 2020 16:57:27 GMT
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 235
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 32 bytes (0x20)
0000: Access-Control-Allow-Origin: *
<= Recv header, 67 bytes (0x43)
0000: Set-Cookie: flash=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GM
0040: T
<= Recv header, 33 bytes (0x21)
0000: X-Content-Type-Options: nosniff
<= Recv header, 17 bytes (0x11)
0000: Via: 1.1 google
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 16 Jul 2020 16:57:27 GMT
<= Recv header, 24 bytes (0x18)
0000: Cache-Control: private
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 235 bytes (0xeb)
0000: {. "ip": "12.xxx.xxx.xxx",. "city": "Seoul",. "region": "xxx
0040: ",. "country": "xxx",. "loc": "xxx",. "org": "xxx
0080: xxx",. "postal": "xxx",. "timezone": "xxx",.
00c0: "readme": "https://ipinfo.io/missingauth".}
{
"ip": "12.xxx.xxx.xxx",
"city": "xxx",
"region": "xxx",
"country": "xxx",
"loc": "37xxx",
"org": "xxx",
"postal": "xxx",
"timezone": "xxx",
"readme": "https://ipinfo.io/missingauth"
== Info: Connection #0 to host ifconfig.me left intact
인코딩 되지 않은 바디를 포함.
-H: Set header.
헤더 설정.
❑ File download
파일 다운로드
파일 다운로드
$ curl -O https://github.com/blackbird71SR/Hello-World/archive/master.zip
% Total % Received % Xferd Average Speed Time Time Time Current100 130 100 130 0 0 4814 0 --:--:-- --:--:-- --:--:-- 4814
파일 이름을 변경 없이 다운로드.