The first line of the request includes the method - sometimes also referred to as "the verb".
When doing a simple GET request as this command line would do:
curl http://example.com/file
…the initial request line looks like this:
GET /file HTTP/1.1
You can tell curl to change the method into something else by using the -X or --request
command-line options followed by the actual method name. You can, for example, send a
DELETE instead of GET like this:
curl http://example.com/file -X DELETE
This command-line option only changes the text in the outgoing request, it does not change
any behavior. This is particularly important if you, for example, ask curl to send a HEAD with
-X , as HEAD is specified to send all the headers a GET response would get but never
send a response body, even if the headers otherwise imply that one would come. So, adding
-X HEAD to a command line that would otherwise do a GET will cause curl to hang, waiting
for a response body that won't come.
When asking curl to perform HTTP transfers, it will pick the correct method based on the
option so you should only very rarely have to explicitly ask for it with -X . It should also be
noted that when curl follows redirects like asked to with -L , the request method set with -
X will be sent even on the subsequent redirects.
HTTP POST ( -d or --data)
POST is the HTTP method that was invented to send data to a receiving web application,
and it is how most common HTML forms on the web works. It usually sends a chunk of
relatively small amounts of data to the receiver.
When the data is sent by a browser after data have been filled in a form, it will send it "URL
encoded", as a serialized name=value pairs separated with ampersand symbols ('&'). You
send such data with curl's -d or --data option like this:
curl -d 'name=admin&shoesize=12' http://example.com/
When specifying multiple -d options on the command line, curl will concatenate them and
insert ampersands in between, so the above example could also be made like this:
curl -d name=admin -d shoesize=12 http://example.com/
If the amount of data to send isn't really fit to put in a mere string on the command line, you
can also read it off a file name in standard curl style:
curl -d @filename http://example.com
Content-Type
POSTing with curl's -d option will make it include a default header that looks like Content-
Type: application/x-www-form-urlencoded . That's what your typical browser will use for a
plain POST.
Many receivers of POST data don't care about or check the Content-Type header.
If that header is not good enough for you, you should, of course, replace that and instead
provide the correct one. Such as if you POST JSON to a server and want to more accurately
tell the server about what the content is:
curl -d '{json}' -H 'Content-Type: application/json' https://example.com