JSON over POST with curl (to pylons)
I have a pylons con开发者_高级运维troller 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?
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
精彩评论