Curl offers a series of different http method calls that are prefixed with a X, but also offers the same methods without. I've tried both and I can't seem to figure out the difference. Can someone explain to me quickly how these two operations differ?
相关问题
- Google Apps Script: testing doPost() with cURL
- Can I skip certificate verification oracle utl_htt
- Requests Library Force Use of HTTP/1.1 On HTTPS Pr
- Change curl SSL Version
- What means data-urlencode in CURL?
相关文章
- Programmatically scraping a response header within
- What to do with extra HTTP header from proxy?
- How can I immediately cancel a curl operation?
- Get Amazon MWS results to Json or Xml and elaborat
- POST csv/Text file using cURL
- curl: (3) Illegal characters found in URL
- How to force CURL to ask for http/1.1? Or maybe th
- Facebook API error subcode 33
-x [your method]
x let you override the default 'Get'
Perhaps I am not following your question, but it looks like there is the option -G which is just telling curl to use the GET method and then there is the -X option which lets you make the methods anything you want. So curl -G and curl -XGET would be the same thing. I don't see a -GET it seems that curl just ignores anything after -G.
By default you use curl without explicitly saying which request method to use. If you just pass in a HTTP URL like
curl http://example.com
it will use GET. If you use-d
or-F
curl will use POST,-I
will cause a HEAD and-T
will make it a PUT.If for whatever reason you're not happy with these default choices that curl does for you, you can override those request methods by specifying
-X [WHATEVER]
. This way you can for example send a DELETE by doingcurl -X DELETE [URL]
.It is thus pointless to do
curl -XGET [URL]
as GET would be used anyway. In the same vein it is pointless to docurl -X POST -d data [URL]...
But you can make a fun and somewhat rare request that sends a request-body in a GET request with something likecurl -X GET -d data [URL]
.Digging deeper
curl -GET
(using a single dash) is just wrong for this purpose. That's the equivalent of specifying the-G
,-E
and-T
options and that will do something completely different.There's also a curl option called
--get
to not confuse matters with either. It is the long form of -G, which is used to convert data specified with-d
into a GET request instead of a POST.(I subsequently used my own answer here to populate the curl FAQ to cover this.)
Warnings
Modern versions of curl will inform users about this unnecessary and potentially harmful use of -X when verbose mode is enabled (
-v
) - to make users aware. Further explained and motivated in this blog post.-G converts a POST + body to a GET + query
You can ask curl to convert a set of
-d
options and instead of sending them in the request body with POST, put them at the end of the URL's query string and issue a GET, with the use of `-G. Like this: