开发者

JSON over POST with curl (to pylons)

开发者 https://www.devze.com 2023-03-29 18:55 出处:网络
I have a pylons con开发者_高级运维troller action that accepts POST @restrict(\'POST\') def myaction(self):

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号