Curl

From 탱이의 잡동사니
Jump to: navigation, search

Overview

Linux command curl 사용법 정리

Options

-k, --insecure

SSL 인증 확인을 하지 않는다. 예를 들어, https 통신을 할 때, 상대방 SSL 인증서를 검증하지 않는다.

-u, --user <user:password;options>

user name, password 를 지정한다.

Specify the user name, password and optional login options to use for server authentication. Overrides -n, --netrc and --netrc-optional.

If you simply specify the user name, with or without the login options, curl will prompt for a password.

If  you  use an SSPI-enabled curl binary and perform NTLM authentication, you can force curl to select the user name and password from your environment
by simply specifying a single colon with this option: "-u :" or by specfying the login options on their own, for example "-u ;auth=NTLM".

You can use the optional login options part to specify protocol specific options that may be used during authentication. At present only IMAP, POP3 and
SMTP  support  login options as part of the user login information. For more information about the login options please see RFC 2384, RFC 5092 and IETF
draft draft-earhart-url-smtp-00.txt (Added in 7.31.0).

If this option is used several times, the last one will be used.

Example

$ curl -vX GET http://127.0.0.1:8081/simple/ --user pchero:1234
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
* Server auth using Basic with user 'pchero'
> GET /simple/ HTTP/1.1
> Authorization: Basic cGNoZXJvOjEyMzQ=
> User-Agent: curl/7.35.0
...

-X, --request <command>

GET, HEAD, POST, PUT 과 같은 Method 방식을 지정한다.

(HTTP) Specifies a custom request method to use when communicating with the HTTP server.  The specified request will be used instead of the method oth‐
erwise  used  (which  defaults  to  GET). Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and
DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.

Normally you don't need this option. All sorts of GET, HEAD, POST and PUT requests are rather invoked by using dedicated command line options.

This option only changes the actual word used in the HTTP request, it does not alter the way curl behaves. So for example if you want to make a  proper
HEAD request, using -X HEAD will not suffice. You need to use the -I, --head option.

(FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with FTP.

(POP3) Specifies a custom POP3 command to use instead of LIST or RETR. (Added in 7.26.0)

(IMAP) Specifies a custom IMAP command to use insead of LIST. (Added in 7.30.0)

(SMTP) Specifies a custom SMTP command to use instead of HELP or VRFY. (Added in 7.34.0)

If this option is used several times, the last one will be used.

-d, --data <data>

Request 전송할 때, 데이터도 같이 전송한다.

(HTTP)  Sends  the  specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and
presses the submit button. This will cause curl to pass the data to the server using the content-type  application/x-www-form-urlencoded.   Compare  to
-F, --form.

-d,  --data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form
field you may use --data-urlencode.

If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating  &-symbol.
Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'.

If  you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Mul‐
tiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar. When --data is told to read  from  a
file like that, carriage returns and newlines will be stripped out.

-L, --location

만약 해당 페이지가 다른 곳으로 옮겨졌을 때(3XX response code), 자동으로 옮겨진 곳으로 다시 request 를 전송한다.

Examples

ssl certification no check

$ curl -k -v https://web_sites.com

POST with data

$ curl 127.0.0.1:8081 -X POST -d 'test data 123'

POST with binary data

$ curl -k -X POST -H "Content-Type: application/json" \
--data-binary '{ "message": {"username":"test username","password":"4ff5ff499cf340f13d2c4c95859712da"} }' https://pchero21.com:8080/auth