|
tl;dr: how do I handle POST requests in my cherrypy web app? I'm trying to build a simple API in CherryPy that takes POST requests from an iPhone app and returns JSON. I'm converting an old PHP project, so PHP is what I'm familiar with. I'm new to Python. I'm trying to test my script's handling of POST requests like this: curl -d "key1=value1" http://<username>.webfactional.com/ When I curl without the -d, the return value loads fine; however, when I curl -d, I get a 400 Bad Request: Bad syntax or unsupported method. I don't know the "right" way to handle a POST request, so I'm trying one I found at http://stackoverflow.com/a/464977/255489: from cherrypy import request
# Root class, index() method...
return request.params['key1']
But this gives me a Edit as per Johns's question: When I curl without any {my IP address} - - [16/Apr/2012:00:05:18 -0500]
"GET / HTTP/1.1" 500 805 "-" "curl/7.21.4 (universal-apple-darwin11.0)
libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5"
and this in the error log: 2012/04/16 00:05:19 [info] 20703#0: *123544253 client {my IP address}
closed keepalive connection
Hope this helps. |
|
Found some useful documentation here. Basically you must declare the objects as keyword arguments in the function. The function should look something like this,
|