Curl: Difference between revisions
(Created page with "=Internal= * Linux * wget !!!Download a file and write it locally {{{ curl -O http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz }}} !!!Send REST invoca...") |
No edit summary |
||
Line 5: | Line 5: | ||
=Download a file and write it locally= | |||
<pre> | |||
curl -O http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz | curl -O http://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz | ||
</pre> | |||
=Send REST invocations= | |||
==GET== | |||
<pre> | |||
curl -X GET http://localhost:8080/amgen-paas/project/ | curl -X GET http://localhost:8080/amgen-paas/project/ | ||
</pre> | |||
==POST== | |||
<pre> | |||
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/amgen-paas/project/MyProject | http://localhost:8080/amgen-paas/project/MyProject | ||
</pre> | |||
==PUT== | |||
<pre> | |||
curl -X PUT -d arg=val -d arg=val http://localhost:8080/amgen-paas/project/MyProject | curl -X PUT -d arg=val -d arg=val http://localhost:8080/amgen-paas/project/MyProject | ||
</pre> | |||
==DELETE== | |||
<pre> | |||
curl -X DELETE http://localhost:8080/amgen-paas/project/MyProject | curl -X DELETE http://localhost:8080/amgen-paas/project/MyProject | ||
</pre> | |||
=Command Line Configuration= | |||
==-X== | |||
The HTTP method. | The HTTP method. | ||
==-H== | |||
Specifies a request header. Multiple headers can be specified. Example: | Specifies a request header. Multiple headers can be specified. Example: | ||
<pre> | |||
curl -H "Authentication Bearer: <token>" -H "Content-Type: application/json" ... | curl -H "Authentication Bearer: <token>" -H "Content-Type: application/json" ... | ||
</pre> | |||
===Content-Type=== | |||
<pre> | |||
-H "Content-Type: application/json" | |||
</pre> | |||
==-u== | |||
Authentication: | Authentication: | ||
<pre> | |||
curl -u username:password | curl -u username:password | ||
</pre> | |||
==-k --insecure== | |||
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. | 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. | 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. | 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 <data>== | |||
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. | 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. | ||
Line 103: | Line 92: | ||
===-d and GET=== | |||
If -d is used with GET, the data is sent as a [entity-body | If -d is used with GET, the data is sent as a [[HTTP#HTTPRequestEntityBody|entity-body]. | ||
==-I== | |||
HEAD only. | HEAD only. | ||
=Simulation of a HTTP Session JSessionID= | |||
<pre> | |||
curl -b "JSESSIONID=e1VBIIBFhyjU2PLU0JFNwqYu" http://localhost:8080/session-servlet/ | curl -b "JSESSIONID=e1VBIIBFhyjU2PLU0JFNwqYu" http://localhost:8080/session-servlet/ | ||
</pre> | |||
Revision as of 18:47, 4 January 2017
Internal
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/amgen-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/amgen-paas/project/MyProject
PUT
curl -X PUT -d arg=val -d arg=val http://localhost:8080/amgen-paas/project/MyProject
DELETE
curl -X DELETE http://localhost:8080/amgen-paas/project/MyProject
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 [[HTTP#HTTPRequestEntityBody|entity-body].
-I
HEAD only.
Simulation of a HTTP Session JSessionID
curl -b "JSESSIONID=e1VBIIBFhyjU2PLU0JFNwqYu" http://localhost:8080/session-servlet/