Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON over POST with curl (to pylons)

I have a pylons controller action that accepts POST

@restrict('POST')
def myaction(self):

    payload = json.loads(request.body)

I put properly formed JSON (I can do json.loads on it from python command line) in a file.

I am using the following command to send it to the controller:

$ curl -F payload=@./myfile -X POST -H 'Content-type:application/json' -v http://localhost:5000/mycontroller/myaction

on the controller side I'm expecting well formed JSON, but instead of getting JSON in request.body I'm getting a string with other stuff like

-----------------------6588b6680ebb\r\nContent-Disposition: form-data;

before the string containing a string representation of JSON I sent to myaction

What am I doing wrong?

like image 819
AnalyticsBuilder Avatar asked Dec 06 '25 01:12

AnalyticsBuilder


1 Answers

The option -F is for multipart content, you should use --data / -d instead:

$ curl --data @./myfile -X POST -H 'Content-type:application/json' -v http://localhost:5000/mycontroller/myaction
like image 186
alexisdm Avatar answered Dec 07 '25 17:12

alexisdm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!