Curl: Difference between revisions
No edit summary |
|||
Line 81: | Line 81: | ||
<pre> | <pre> | ||
curl -X GET http://localhost:8080/ | curl -X GET http://localhost:8080/novaordis-paas/project/ | ||
</pre> | </pre> | ||
Line 89: | Line 89: | ||
curl -H "Content-Type: application/json" -X POST \ | curl -H "Content-Type: application/json" -X POST \ | ||
-d '{"id":"1","name":"MyProject","team":"A","language":"java","size":"small"}' \ | -d '{"id":"1","name":"MyProject","team":"A","language":"java","size":"small"}' \ | ||
http://localhost:8080/ | http://localhost:8080/novaordis-paas/project/MyProject | ||
</pre> | </pre> | ||
Line 95: | Line 95: | ||
<pre> | <pre> | ||
curl -X PUT -d arg=val -d arg=val http://localhost:8080/ | curl -X PUT -d arg=val -d arg=val http://localhost:8080/novaordis-paas/project/MyProject | ||
</pre> | </pre> | ||
Line 101: | Line 101: | ||
<pre> | <pre> | ||
curl -X DELETE http://localhost:8080/ | curl -X DELETE http://localhost:8080/novaordis-paas/project/MyProject | ||
</pre> | </pre> | ||
Revision as of 22:35, 27 November 2017
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
-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.
-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
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