I have a cerrypy service running very well, it contains a form that only has a textarea, the input text is transformed by RE inside the same service and gives back the transformed text in the screen, the thing is that now I need to send the data from the command line, I've tried with curl following the documentation found here: http://curl.haxx.se/docs/httpscripting.html#Forms_explained, but I can not make it work:
the form is this:
<form method="POST" action="NMT">
<div><table width=100% bgcolor="D2CAC1"><tr><td>
<textarea class="richtextbox" name="contents" style="width:100%;height:300px">
</textarea>
</td></tr></table></div>
<a title="unificar"><input type="submit" value=" trapümün " /></a>
</form>
And the function is this:
#define form function
def NMT(self, contents=None):
if not contents:
return """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NMT - Norwirin Mapudungun Trapümfe</title></head>
<body><font face=arial>Inserte el texto para unificar<br><a href=.>Inténtelo de nuevo</a></fon>
</body></html>"""
I've tried this:
curl --data-urlencode "contents=zomo" http://www.chandia.net:8080
curl --data "contents=zomo" http://www.chandia.net:8080
curl --data "contents=zomo&submit=%20trapümün%20" http://89.140.140.36:8080
I've also changed the POST to GET to try this:
curl "http://www.chandia.net:8080?contents=zomo"
curl "http://www.chandia.net:8080?contents=zomo&trapümün"
curl "http://www.chandia.net:8080?contents=zomo&%20trapümün%20"
curl "http://www.chandia.net:8080?contents=zomo&submit=%20trapümün%20"
The results it changes a bit but always says:
<body>
<h2>400 Bad Request</h2>
<p>Unexpected body parameters: contents</p>
<pre id="traceback">Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 40, in __call__
raise sys.exc_info()[1]
HTTPError: (400, 'Unexpected body parameters: contents')
Any suggestions, or maybe there is another way to do it....?
thanks in advance
your handler definition must include the following...
def NMT(self, contents)
or
def NMT(self, *args, **kwargs)
EDIT: you'll need to specific the handler in your url.
curl --data-urlencode "contents=zomo" http://www.chandia.net:8080/NMT
Hope this helps!