curl-users
Re: A small nudge to fix a frequent -X misuse?
Date: Mon, 31 Aug 2015 17:40:06 +0200
Hi
Am 30-08-2015 20:14, schrieb Alex Bligh:
> On 30 Aug 2015, at 17:36, Daniel Stenberg <daniel_at_haxx.se> wrote:
>
>> Like they may then wrongly believe that curl would act differently if
>> you did -XPOST or -XGET, when in fact curl doesn't care about what -X
>> is set to, but it is the other option(s) that control how it behaves.
>
> Really? I'm feeling slightly sensitive about this as it took me a
> little while yesterday to work out why my otherwise working script
> failed when I added a '-d' component - I'd not explicitly set '-X GET'
> but relied on it being the default. I thought in such a circumstance
> (presence of -d), '-X GET' did explicitly change the HTTP action from
> POST to GET.
>
> Bottom of the (working) script looks like this:
>
> # Run curl to call the endpoint, passing the output through json_pp
> merely to
> # make it pretty.
> set -x
> curl -s -X GET -u
> "${JOB_ADMIN_USER}/${JOB_ADMIN_UUID}:${JOB_ADMIN_PASSWORD}"
> "${ENDPOINT}${API_CALL}" -d "measureKeys=${MEASURE_KEYS}" -d
> "resourceUUID=${RESOURCE_UUID_ARRAY}" | ${JSON_PP}
>
> Removing '-X GET' breaks it, as it uses 'POST' instead of 'GET'.
Just for my curiosity.
Why don't using
-G
http://curl.haxx.se/docs/manpage.html
###########
-G, --get
When used, this option will make all data specified with -d, --data,
--data-binary or --data-urlencode to be used in an HTTP GET request
instead of the POST request that otherwise would be used. The data will
be appended to the URL with a '?' separator.
If used in combination with -I, the POST data will instead be appended
to the URL with a HEAD request.
If this option is used several times, only the first one is used. This
is because undoing a GET doesn't make sense, but you should then instead
enforce the alternative method you prefer.
###########
> Obviously under your proposal in the above circumstance it won't
> produce the warning anyway. However, anyone reading that example and
> an example without '-d' will have to understand how curl changes the
> HTTP action depending on presence of '-d'.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-08-31