2014-06-23 33 views
0

我有一个cerrypy服务,它运行得非常好,它包含一个只有textarea的表单,输入文本在RE中由同一个服务转换并返回已转换的文本在屏幕上,事情是,现在我需要从命令行发送数据,我试着用curl下面的文档找到这里:http://curl.haxx.se/docs/httpscripting.html#Forms_explained,但我不能让它工作:如何使用curl填充cherrypy web服务中的表单

形式是这样的:

<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&uuml;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去试试这个:

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') 

任何建议,或者也许有另一种方式来做到这一点....?

在此先感谢

回答

1

处理程序定义必须包括以下内容...

def NMT(self, contents) 

def NMT(self, *args, **kwargs) 

编辑: 你需要特定的处理程序在您的网址。

curl --data-urlencode "contents=zomo" http://www.chandia.net:8080/NMT 

希望这有助于!

+0

我添加了编辑原始问题的内容,对吗? –

+0

实际上如果你看到我尝试过的东西,你建议的是其中之一:curl --data-urlencode“contents = zomo”http://www.chandia.net:8080 –

+0

你的问题中的卷曲请求不要让你去/ NMT处理程序。默认情况下,请求将由def索引处理。哪些目前不接受变量内容。所以你看到的错误是准确的。 –

相关问题