CURL Command Line URL Parameters

I am trying to send a DELETE request with url parameter using CURL. I do:

 curl -H application/x-www-form-urlencoded -X DELETE http://localhost:5000/locations` -d 'id=3' 

However, the server does not see the id = 3 parameter. I tried to use some kind of GUI application, and when I pass the URL as: http://localhost:5000/locations?id=3 , it works. I would really prefer to use CURL rather than this GUI application. Can someone point out what I'm doing wrong?

+84
curl
Nov 14 '12 at 12:30
source share
3 answers

"application / x-www-form-urlencoded" header, why? Try:

 curl -X DELETE 'http://localhost:5000/locations?id=3' 

or

 curl -X GET 'http://localhost:5000/locations?id=3' 
+137
Nov 14
source share

Felipsmartins is correct.

It should be noted that this is because you cannot use the -d / - data option unless it is a POST request. But this is possible if you use the -G option.

This means you can do this:

 curl -X DELETE -G 'http://localhost:5000/locations' -d 'id=3' 

This is a little silly here, but when you are on the command line and you have a lot of options, it is much more complicated.

I say this because cURL commands are usually quite long, so you should do this on multiple lines, avoiding line breaks.

 curl -X DELETE -G \ 'http://localhost:5000/locations' \ -d id=3 \ -d name=Mario \ -d surname=Bros 

This is obviously much more convenient if you are using zsh. I mean, when you need to edit the previous command, because zsh allows you to go line by line. (just saying)

Hope this helps.

+65
Jan 11 '13 at 18:34
source share

If your parameter is a number, you can also do this:

curl -X DELETE localhost:5000/locations/3

Where 3 'is your parameter .

-four
Apr 26 '16 at 19:08
source share



All Articles