Curl D Example

cURL -d . parameter – Stack Overflow

Whenever your have a doubt use man.
Issue man curl and read about -d switch.
-d, –data
(HTTP) Sends the specified data in a POST request to the HTTP
cause curl to pass the data to the server using the content-type
-d, –data is the same as –data-ascii. –data-raw is almost the
ter. To post data purely binary, you should instead use the
[… ]
It allows you to send ASCII data, eg. :
curl -d ‘{“hello”: “world”}’ -X POST -H “Content-Type: application/json”
Send a JSON string to the server.
In your example, it just send a. character as ASCII data to the server. What it does depends on the server logic and is out of the curl command scope.
This said, we can guess what a. (dot, period, full stop) might mean in computer science:
Dot is a placeholder for the current directory in Unix File Systems;
Dot is a wildcard for any character in most Regular Expression grammars;
Dot is the separator between labels in domain name;
Dot is a common separator for filename and extension;
Nota: It is considered as a bad practice to send credentials using GET parameters, avoid it if you can and read more.
curl POST examples - gists · GitHub

curl POST examples – gists · GitHub

Common Options
-#, –progress-bar
Make curl display a simple progress bar instead of the more informational standard meter.
-b, –cookie
Supply cookie with request. If no =, then specifies the cookie file to use (see -c).
-c, –cookie-jar
File to save response cookies to.
-d, –data
Send specified data in POST request. Details provided below.
-f, –fail
Fail silently (don’t output HTML error form if returned).
-F, –form
Submit form data.
-H, –header

Headers to supply with request.
-i, –include
Include HTTP headers in the output.
-I, –head
Fetch headers only.
-k, –insecure
Allow insecure connections to succeed.
-L, –location
Follow redirects.
-o, –output
Write output to. Can use –create-dirs in conjunction with this to create any directories
specified in the -o path.
-O, –remote-name
Write output to file named like the remote file (only writes to current directory).
-s, –silent
Silent (quiet) mode. Use with -S to force it to show errors.
-v, –verbose
Provide more information (useful for debugging).
-w, –write-out Make curl display information on stdout after a completed transfer. See man page for more details on
available variables. Convenient way to force curl to append a newline to output: -w “\n” (can add
to ~/).
-X, –request
The request method to use.
When sending data via a POST or PUT request, two common formats (specified via the Content-Type header) are:
Many APIs will accept both formats, so if you’re using curl at the command line, it can be a bit easier to use the form urlencoded format instead of json because
the json format requires a bunch of extra quoting
curl will send form urlencoded by default, so for json the Content-Type header must be explicitly set
This gist provides examples for using both formats, including how to use sample data files in either format with your curl requests.
curl usage
For sending data with POST and PUT requests, these are common curl options:
request type
content type header
-H “Content-Type: application/x-www-form-urlencoded”
-H “Content-Type: application/json”
form urlencoded: -d “param1=value1&param2=value2” or -d
json: -d ‘{“key1″:”value1”, “key2″:”value2”}’ or -d
POST application/x-www-form-urlencoded
application/x-www-form-urlencoded is the default:
curl -d “param1=value1&param2=value2” -X POST localhost:3000/data
curl -d “param1=value1&param2=value2” -H “Content-Type: application/x-www-form-urlencoded” -X POST localhost:3000/data
with a data file
curl -d “” -X POST localhost:3000/data
POST application/json
curl -d ‘{“key1″:”value1”, “key2″:”value2”}’ -H “Content-Type: application/json” -X POST localhost:3000/data
curl -d “” -X POST localhost:3000/data
curl.1 the man page

curl.1 the man page

curl – transfer a URL Synopsis
curl [options / URLs] Description
curl is a tool for transfering data from or to a server. It supports these protocols: DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET or TFTP. The command is designed to work without user interaction.
curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume and more. As you will see below, the number of features will make your head spin!
curl is powered by libcurl for all transfer-related features. See libcurl(3) for details. Url
The URL syntax is protocol-dependent. You’ll find a detailed description in RFC 3986.
You can specify multiple URLs or parts of URLs by writing part sets within braces and quoting the URL as in:
“one, two, three}”
or you can get sequences of alphanumeric series by using [] as in:
“001-100]” (with leading zeros)
Nested sequences are not supported, but you can use several ones next to each other:
“1996-1999]/vol[1-4]/part{a, b, c}”
You can specify any amount of URLs on the command line. They will be fetched in a sequential manner in the specified order. You can specify command line options and URLs mixed and in any order on the command line.
You can specify a step counter for the ranges to get every Nth number or letter:
When using [] or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example ‘&’, ‘? ‘ and ‘*’.
Provide the IPv6 zone index in the URL with an escaped percentage sign and the interface name. Like in
If you specify URL without protocol prefix, curl will attempt to guess what protocol you might want. It will then default to HTTP but try other protocols based on often-used host name prefixes. For example, for host names starting with “ftp. ” curl will assume you want to speak FTP.
curl will do its best to use what you pass to it as a URL. It is not trying to validate it as a syntactically correct URL by any means but is instead very liberal with what it accepts.
curl will attempt to re-use connections for multiple file transfers, so that getting many files from the same server will not do multiple connects / handshakes. This improves speed. Of course this is only done on files specified on a single command line and cannot be used between separate curl invocations. Output
If not told otherwise, curl writes the received data to stdout. It can be instructed to instead save that data into a local file, using the -o, –output or -O, –remote-name options. If curl is given multiple URLs to transfer on the command line, it similarly needs multiple options for where to save them.
curl does not parse or otherwise “understand” the content it gets or writes as output. It does no encoding or decoding, unless explicitly asked to with dedicated command line options. Protocols
curl supports numerous protocols, or put in URL terms: schemes. Your particular build may not support them all.
Lets you lookup words using online dictionaries.
Read or write local files. curl does not support accessing file URL remotely, but when running on Microsoft Windows using the native UNC approach will work.
curl supports the File Transfer Protocol with a lot of tweaks and levers. With or without using TLS.
Retrieve files.
curl supports HTTP with numerous options and variations. It can speak HTTP version 0. 9, 1. 0, 1. 1, 2 and 3 depending on build options and the correct command line options.
Using the mail reading protocol, curl can “download” emails for you. With or without using TLS.
curl can do directory lookups for you, with or without TLS.
curl supports MQTT version 3. Downloading over MQTT equals “subscribe” to a topic while uploading/posting equals “publish” on a topic. MQTT over TLS is not supported (yet).
Downloading from a pop3 server means getting a mail. With or without using TLS.
The Realtime Messaging Protocol is primarily used to server streaming media and curl can download it.
curl supports RTSP 1. 0 downloads.
curl supports SSH version 2 scp transfers.
curl supports SFTP (draft 5) done over SSH version 2.
curl supports SMB version 1 for upload and download.
Uploading contents to an SMTP server means sending an email. With or without TLS.
Telling curl to fetch a telnet URL starts an interactive session where it sends what it reads on stdin and outputs what the server sends it.
curl can do TFTP downloads and uploads. Progress meter
curl normally displays a progress meter during operations, indicating the amount of transferred data, transfer speeds and estimated time left, etc. The progress meter displays number of bytes and the speeds are in bytes per second. The suffixes (k, M, G, T, P) are 1024 based. For example 1k is 1024 bytes. 1M is 1048576 bytes.
curl displays this data to the terminal by default, so if you invoke curl to do an operation and it is about to write data to the terminal, it disables the progress meter as otherwise it would mess up the output mixing progress meter and response data.
If you want a progress meter for HTTP POST or PUT requests, you need to redirect the response output to a file, using shell redirect (>), -o, –output or similar.
This does not apply to FTP upload as that operation does not spit out any response data to the terminal.
If you prefer a progress “bar” instead of the regular meter, -#, –progress-bar is your friend. You can also disable the progress meter completely with the -s, –silent option. Options
Options start with one or two dashes. Many of the options require an additional value next to them.
The short “single-dash” form of the options, -d for example, may be used with or without a space between it and its value, although a space is a recommended separator. The long “double-dash” form, -d, –data for example, requires a space between it and its value.
Short version options that don’t need any additional values can be used immediately next to each other, like for example you can specify all the options -O, -L and -v at once as -OLv.
In general, all boolean options are enabled with –option and yet again disabled with –no-option. That is, you use the exact same option name but prefix it with “no-“. However, in this list we mostly only list and show the –option version of them.
–abstract-unix-socket (HTTP) Connect through an abstract Unix domain socket, instead of using the network. Note: netstat shows the path of an abstract socket prefixed with ‘@’, however the argument should not have this leading character.
Example: curl –abstract-unix-socket socketpath
Added in 7. 53. 0.
(HTTPS) This option enables the alt-svc parser in curl. If the file name points to an existing alt-svc cache file, that will be used. After a completed transfer, the cache will be saved to the file name again if it has been modified.
Specify a “” file name (zero length) to avoid loading/saving and make curl just handle the cache in memory.
If this option is used several times, curl will load contents from all the files but the last one will be used for saving.
Example: curl –alt-svc
Added in 7. 64. 1.
(HTTP) Tells curl to figure out authentication method by itself, and use the most secure one the remote site claims to support. This is done by first doing a request and checking the response-headers, thus possibly inducing an extra network round-trip. This is used instead of setting a specific authentication method, which you can do with –basic, –digest, –ntlm, and –negotiate.
Using –anyauth is not recommended if you do uploads from stdin, since it may require data to be sent twice and then the client must be able to rewind. If the need should arise when uploading from stdin, the upload operation will fail.
Used together with -u, –user.
Example: curl –anyauth –user me:pwd
See also –proxy-anyauth, –basic and –digest.
-a, –append
(FTP SFTP) When used in an upload, this makes curl append to the target file instead of overwriting it. If the remote file doesn’t exist, it will be created. Note that this flag is ignored by some SFTP servers (including OpenSSH).
Example: curl –upload-file local –append
(TLS) Tells curl to use the specified certificate file to verify the peer. The file may contain multiple CA certificates. The certificate(s) must be in PEM format. Normally curl is built to use a default file for this, so this option is typically used to alter that default file.
curl recognizes the environment variable named ‘CURL_CA_BUNDLE’ if it is set, and uses the given path as a path to a CA cert bundle. This option overrides that variable.
The windows version of curl will automatically look for a CA certs file named ´´, either in the same directory as, or in the Current Working Directory, or in any folder along your PATH.
If curl is built against the NSS SSL library, the NSS PEM PKCS#11 module () needs to be available for this option to work properly.
(iOS and macOS only) If curl is built against Secure Transport, then this option is supported for backward compatibility with other SSL engines, but it should not be set. If the option is not set, then curl will use the certificates in the system and user Keychain to verify the peer, which is the preferred method of verifying the peer’s certificate chain.
(Schannel only) This option is supported for Schannel in Windows 7 or later with libcurl 7. 60 or later. This option is supported for backward compatibility with other SSL engines; instead it is recommended to use Windows’ store of root certificates (the default for Schannel).
If this option is used several times, the last one will be used.
Example: curl –cacert

(TLS) Tells curl to use the specified certificate directory to verify the peer. Multiple paths can be provided by separating them with “:” (e. g. “path1:path2:path3”). The certificates must be in PEM format, and if curl is built against OpenSSL, the directory must have been processed using the c_rehash utility supplied with OpenSSL. Using –capath can allow OpenSSL-powered curl to make SSL-connections much more efficiently than using –cacert if the –cacert file contains many CA certificates.
If this option is set, the default capath value will be ignored, and if it is used several times, the last one will be used.
Example: curl –capath /local/directory
(TLS) Tells curl to verify the status of the server certificate by using the Certificate Status Request (aka. OCSP stapling) TLS extension.
If this option is enabled and the server sends an invalid (e. expired) response, if the response suggests that the server certificate has been revoked, or no response at all is received, the verification fails.
This is currently only implemented in the OpenSSL, GnuTLS and NSS backends.
Example: curl –cert-status
Added in 7. 41. 0.
(TLS) Tells curl what type the provided client certificate is using. PEM, DER, ENG and P12 are recognized types. If not specified, PEM is assumed.
Example: curl –cert-type PEM –cert file
See also -E, –cert, –key and –key-type.
-E, –cert
(TLS) Tells curl to use the specified client certificate file when getting a file with HTTPS, FTPS or another SSL-based protocol. The certificate must be in PKCS#12 format if using Secure Transport, or PEM format if using any other engine. If the optional password isn’t specified, it will be queried for on the terminal. Note that this option assumes a “certificate” file that is the private key and the client certificate concatenated! See -E, –cert and –key to specify them independently.
If curl is built against the NSS SSL library then this option can tell curl the nickname of the certificate to use within the NSS database defined by the environment variable SSL_DIR (or by default /etc/pki/nssdb). If the NSS PEM PKCS#11 module () is available then PEM files may be loaded. If you want to use a file from the current directory, please precede it with “. /” prefix, in order to avoid confusion with a nickname. If the nickname contains “:”, it needs to be preceded by “\” so that it is not recognized as password delimiter. If the nickname contains “”\””

Frequently Asked Questions about curl d example

Leave a Reply

Your email address will not be published. Required fields are marked *