Curl -GET and -X GET

Curl offers a number of different http method calls that have the X prefix, but also offers the same methods without. I tried both and I can not understand the difference. Can someone quickly explain to me how these two operations differ?

+111
Dec 14 '11 at 1:01
source share
3 answers

By default, you use curl without explicitly specifying which request method to use. If you just pass an HTTP url like curl http://example.com , it will use GET. If you use -d or -F , curl will use POST, -I will cause HEAD and -T do this PUT.

If for some reason you are not happy with these default options that curl for you, you can override these query methods by specifying -X [WHATEVER] . Thus, you can, for example, send DELETE by executing curl -X DELETE [URL] .

Thus, it makes no sense to do curl -XGET [URL] , since GET will be used anyway. In the same vein, it curl -X POST -d data [URL]... no sense to do curl -X POST -d data [URL]... But you can make a funny and somewhat rare request that sends the request body to a GET request with something like curl -X GET -d data [URL] .

Digging deeper

curl -GET (using a single dash) is simply wrong for this purpose. This is equivalent to specifying -G , -E and -T , and it will do something completely different.

There is also a waving option called --get so as not to confuse issues with them. This is the long form of -G, which is used to convert the data specified in -d to a GET request instead of POST.

(Subsequently, I used my own answer to fill in the wrap FAQ .

Warnings in 7.45.0 and later

In modern versions of curl, it will inform users of this unnecessary use of -X when the detail mode ( -v ) is on - so that users know. Further explanation and motivation in this blog post .

+236
Dec 14 '11 at 9:20
source share

-x [your method]
x allows you to override the default value of Get

+3
Jan 31 '17 at 17:42
source share

I may not follow your question, but it looks like there is an -G option that just says curl to use the GET method, and then there is an -X option that allows you to do whatever you want. Thus, curl -G and curl -XGET will be the same. I don't see -GET, it seems that curl just ignores anything after -G.

-one
Dec 14 '11 at 1:12
source share



All Articles