Curl: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 49: Line 49:


Turns on silent  or quiet mode. In silent mode curl does not show progress meter or error messages.
Turns on silent  or quiet mode. In silent mode curl does not show progress meter or error messages.
==-S, --show-error==
Like silent more, it disables progress meter, but shows error messages.


==-i==
==-i==

Revision as of 06:00, 1 June 2018

Internal

Command Line Configuration

-X

The HTTP method.

-H

Specifies a request header. Multiple headers can be specified. Example:

curl -H "Authentication Bearer: <token>" -H "Content-Type: application/json" ...

Content-Type

-H "Content-Type: application/json"

-u

Authentication:

curl -u username:password

--basic

Basic Authentication

--digest

Digest Authentication

-k --insecure

Insecure.

-v

Verbose. Shows more details about the request and response. A line starting with '>' means "header data" sent by curl, '<' means "header data" received by curl that is hidden in normal cases, and a line starting with '*' means additional info provided by curl.

-s, --silent

Turns on silent or quiet mode. In silent mode curl does not show progress meter or error messages.

-S, --show-error

Like silent more, it disables progress meter, but shows error messages.

-i

Show the HTTP headers in the output.

-A

Specify the User-Agent string to send to the HTTP server. To encode blanks in the string, surround the string with single quote marks. This can also be set with the -H header option. If this option is used several times, the last one will be used.

-d

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.

If the option 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=alice -d qualification=coder" would generate a post chunk that looks like 'name=alice&qualification=coder'.

If data starts 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. Multiple files can also be specified. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the @ character to have a special interpretation use --data-raw instead.

-d and GET

If -d is used with GET, the data is sent as a entity body.

-I

HEAD only.

Secure Connection

curl https://logging-es:9200/ --capath /etc/kibana/keys --key /etc/kibana/keys/key

Download a file and write it locally

-O instructs curl to write output to a local file name like the remote file we get. Only the file part of the remote file is used. The file will be saved in the current directory.

curl -O http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz

Send REST invocations

GET

curl -X GET http://localhost:8080/novaordis-paas/project/

POST

curl -H "Content-Type: application/json" -X POST \
  -d '{"id":"1","name":"MyProject","team":"A","language":"java","size":"small"}' \
  http://localhost:8080/novaordis-paas/project/MyProject

PUT

curl -X PUT -d arg=val -d arg=val http://localhost:8080/novaordis-paas/project/MyProject

DELETE

curl -X DELETE http://localhost:8080/novaordis-paas/project/MyProject

Simulation of a HTTP Session JSessionID

curl -b "JSESSIONID=e1VBIIBFhyjU2PLU0JFNwqYu" http://localhost:8080/session-servlet/

Parallel Instances

i=0; while [ $i -lt 20 ]; do (curl http://localhost/&); ((i++)); done