cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: HTTP DELETE - how to pass parameters

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 20 May 2009 10:10:45 +0200 (CEST)

On Tue, 19 May 2009, Erik Steffl wrote:

> I am using curl to send HTTP DELETE request and I would like to add some
> parameters to url and encode those parameters, however unlike --get the data
> specified don't end up in URL but in a body instead.

You need to understand that -X only modifies the method keyword in a request,
it doesn't change the underlying behavior. Thus if you use "curl -XDELETE
[URL]" it acts like a GET but sends DELETE instead. If you use "curl -d foo
-XDELETE [URL]" it acts like a POST but sends a DELETE instead.

> When I specify --get and -X DELETE it works as I want it to, not sure if
> that's intended or if it's a bug:
>
> curl --globoff --get -XDELETE http://localhost/project/Resource
> --data-urlencode message='some stuff here to filter resources'
>
> This turns into:
>
> "DELETE /project/Resource?message=fitler url encoded HTTP/1.1\r\nUser-Agent:
> curl/7.18.2 (i486-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3
> libidn/1.10\r\nHost: localhost\r\nAccept: */*\r\n\r\n"
>
> Which is exactly what I want.

Why not just use it that way then?

> However I expected this command to work (no --get, just -XDELETE):
>
> curl --globoff -XDELETE http://localhost/project/Resource --data-urlencode
> message='some stuff here to filter resources'

This won't work since "--data-urlencode" implies POST and you changing the
keyword from POST to DELETE doesn't alter curl's underlying behavior. It will
still send the data exactly like in a POST.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2009-05-20