From e0d884efeba0c041eec21ac40c1869f9e343f716 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 31 Aug 2016 13:33:33 -0500 Subject: [PATCH] curl: Add more download and rewrite data examples (#1023) - Download: first example introduces `-o`, second one introduces `-O`, third example introduces `-L` and `-C` using brackets as per #1018 - Data: first example introduces `-d` (default method is POST and default Content-Type is application/x-www-form-urlencoded), second example introduces `-X` and `-H` - Remove "Head request" - Expand description of "Send form-encoded data" example --- pages/common/curl.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/pages/common/curl.md b/pages/common/curl.md index 1cb594248..bb60426fd 100644 --- a/pages/common/curl.md +++ b/pages/common/curl.md @@ -1,36 +1,32 @@ # curl > Transfers data from or to a server. -> Supports most protocols including HTTP, FTP, POP. +> Supports most protocols including HTTP, FTP, POP3. -- Download a URL to a file: +- Download the contents of an URL to a file: -`curl "{{URL}}" -o {{filename}}` +`curl {{http://example.com}} -o {{filename}}` -- Send form-encoded data: +- Download a file saving the output under the filename indicated by the URL: -`curl --data {{name=bob}} {{http://localhost/form}}` +`curl -O {{http://example.com/filename}}` -- Send JSON data: +- Download a file, following [L]ocation redirects, and automatically [C]ontinuing/resuming a previous file transfer: -`curl -X POST -H "Content-Type: application/json" -d {{'{"name":"bob"}'}} {{http://localhost/login}}` +`curl -O -L -C - {{http://example.com/filename}}` -- Specify an HTTP method: +- Send form-encoded data (POST request of type application/x-www-form-urlencoded): -`curl -X {{DELETE}} {{http://localhost/item/123}}` +`curl -d {{'name=bob'}} {{http://example.com/form}}` -- Head request: +- Send data, specifying a custom HTTP method, and including an extra header: -`curl --head {{http://localhost}}` - -- Include an extra header: - -`curl -H "{{X-MyHeader: 123}}" {{http://localhost}}` +`curl -d {{'{"name":"bob"}'}} -X {{PUT}} -H {{'Content-Type: application/json'}} {{http://example.com/users/1234}}` - Pass a user name and password for server authentication: -`curl -u myusername:mypassword {{http://localhost}}` +`curl -u myusername:mypassword {{http://example.com}}` - Pass client certificate and key for a secure resource: -`curl -v -key {{key.pem}} -cacert {{ca.pem}} -cert {{client.pem}} -k {{https://localhost}}` +`curl -v -key {{key.pem}} -cacert {{ca.pem}} -cert {{client.pem}} -k {{https://example.com}}`