【发布时间】:2014-06-23 14:57:50
【问题描述】:
我有一个运行良好的 Cerrypy 服务,它包含一个只有 textarea 的表单,输入文本在同一个服务中由 RE 转换并在屏幕中返回转换后的文本,问题是现在我需要要从命令行发送数据,我已经按照此处找到的文档尝试使用 curl:http://curl.haxx.se/docs/httpscripting.html#Forms_explained,但我无法使其工作:
表格是这样的:
<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>
功能是这样的:
#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>"""
我试过了:
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
我也将 POST 更改为 GET 来试试这个:
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"
结果它有点变化但总是说:
<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')
任何建议,或者也许有其他方法可以做到......?
提前致谢
【问题讨论】:
标签: php forms curl python-3.x cherrypy