tldr/pages/common/curl.md

37 lines
849 B
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, POP.
2013-12-08 08:56:16 +00:00
- Download a URL to a file:
`curl "{{URL}}" -o {{filename}}`
- Send form-encoded data:
2013-12-08 08:56:16 +00:00
`curl --data {{name=bob}} {{http://localhost/form}}`
2013-12-08 08:56:16 +00:00
- Send JSON data:
2013-12-08 08:56:16 +00:00
`curl -X POST -H "Content-Type: application/json" -d {{'{"name":"bob"}'}} {{http://localhost/login}}`
2013-12-08 08:56:16 +00:00
- Specify an HTTP method:
2013-12-08 08:56:16 +00:00
`curl -X {{DELETE}} {{http://localhost/item/123}}`
2013-12-08 08:56:16 +00:00
- Head request:
2013-12-08 08:56:16 +00:00
`curl --head {{http://localhost}}`
2014-03-11 15:01:45 +00:00
- Include an extra header:
2016-01-12 19:24:22 +00:00
`curl -H "{{X-MyHeader: 123}}" {{http://localhost}}`
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://localhost}}`
2016-01-28 12:12:55 +00:00
- Pass client certificate and key for a secure resource:
`curl -v key {{key.pem}} cacert {{ca.pem}} cert {{client.pem}} -k {{https://localhost}}`