tldr/pages/common/curl.md

38 lines
1.3 KiB
Markdown
Raw Normal View History

2013-12-08 08:56:16 +00:00
# curl
> Transfers data from or to a server.
> Supports most protocols, including HTTP, FTP, and POP3.
> More information: <https://curl.se>.
2013-12-08 08:56:16 +00:00
- Download the contents of an URL to a file:
`curl {{http://example.com}} -o {{filename}}`
- Download a file, saving the output under the filename indicated by the URL:
2013-12-08 08:56:16 +00:00
`curl -O {{http://example.com/filename}}`
2013-12-08 08:56:16 +00:00
2017-02-02 11:35:43 +00:00
- Download a file, following [L]ocation redirects, and automatically [C]ontinuing (resuming) a previous file transfer:
2013-12-08 08:56:16 +00:00
`curl -O -L -C - {{http://example.com/filename}}`
2013-12-08 08:56:16 +00:00
2020-07-21 21:27:14 +01:00
- Send form-encoded data (POST request of type `application/x-www-form-urlencoded`). Use `-d @file_name` or `-d @'-'` to read from STDIN:
2013-12-08 08:56:16 +00:00
`curl -d {{'name=bob'}} {{http://example.com/form}}`
2013-12-08 08:56:16 +00:00
- Send a request with an extra header, using a custom HTTP method:
2013-12-08 08:56:16 +00:00
`curl -H {{'X-My-Header: 123'}} -X {{PUT}} {{http://example.com}}`
- Send data in JSON format, specifying the appropriate content-type header:
`curl -d {{'{"name":"bob"}'}} -H {{'Content-Type: application/json'}} {{http://example.com/users/1234}}`
2016-01-12 19:24:22 +00:00
- Pass a user name and password for server authentication:
2014-03-11 15:01:45 +00:00
`curl -u myusername:mypassword {{http://example.com}}`
2016-01-28 12:12:55 +00:00
- Pass client certificate and key for a resource, skipping certificate validation:
2016-01-28 12:12:55 +00:00
2017-04-19 10:22:34 +01:00
`curl --cert {{client.pem}} --key {{key.pem}} --insecure {{https://example.com}}`