Curl

From 탱이의 잡동사니
Revision as of 13:19, 6 October 2015 by Pchero (talk | contribs) (→‎Examples)
Jump to navigation Jump to search

Overview

Linux command curl 사용법 정리

Options

-k

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.

-X, --request <command>

GET, HEAD, POST, PUT 과 같은 명령들을 지정할 때 사용한다.

(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

curl 을 이용하여 목적지 서버에 데이터를 전달할 때 사용한다.

(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.

Examples

ssl certification no check <source lang=bash> $ curl -k -v https://web_sites.com </source>

POST with data <source lang=bash> $ curl 127.0.0.1:8081 -X POST -d 'test data 123' </source>

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