Using cURL to post data

curlfiddler

I try to post to localhost with some parameters in the URL. Everything just works fine in Fiddler. But cURL doesn't allow me to do it, with the error message below.

curl –data "Task=bake" http://localhost:49301/api/donut/run

{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:49301/api/donut/run'.","MessageDetail":"No action was found on the controller 'Donut' that matches the request."}

In Fiddler I compose the request as follows:
POST http://localhost:49301/api/donut/run?Task=bake

Best Answer

While you might technically be doing a "POST" request in fiddler (Which I've not used, but I do know a thing or two about HTTP), it looks to me very much like you are not actually posting your query, rather you are using a "PUT" (presumably combined with an empty post).

I believe that if you were to use curl http://localhost:49301/api/donut/run?Task=bake it would work fine.

[ A PUT request puts the parameters as part of the URL, a POST request instead puts them in the request header.

Its probable that your application is programmed to accept PUTS but not POSTS.

Related Question