我如何“假”?使用 python 在 ssh 命令行上发送表单 POST 请求?
我有一个关于我编写第一个 Python Web 应用程序时遇到的问题的小问题。
我的网站上有一个表单,其操作是一个 python 文件。表单在发布请求中发布 2 个输入框的值,我的 pythonfile 将捕获这些值并用它们做一些事情。在测试我的程序时,我希望能够在 ssh 中的命令行上发布这些参数,例如:
python twitter.py -user1="bob" -user2="labla"
但是我似乎无法得到它可以工作,但在谷歌上找不到任何东西。
现在我的 python 文件如下所示:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
import nltk
form = cgi.FieldStorage()
reshtml = """Content-Type: text/html\n"""
print reshtml
user1 = form['user1'].value
user2 = form['user2'].value
print user1 + " , " + user2
那么如何使用 python 在 ssh 命令行上“伪造”表单 POST 请求?
I have a small question about a problem I encountered writing my first python web application.
I have a form on my site which action is a python file. The forms posts the values of 2 inputboxes in a post request and my pythonfile will catch those and do something with them. When testing my program I'd like to be able to post these parameters on the command line when in ssh, something like:
python twitter.py -user1="bob" -user2="labla"
However I can't seem to get it to work and couldn't find anything on google.
For now my python file looks like this:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
import nltk
form = cgi.FieldStorage()
reshtml = """Content-Type: text/html\n"""
print reshtml
user1 = form['user1'].value
user2 = form['user2'].value
print user1 + " , " + user2
So how do I 'fake' a form POST request on the commandline in ssh with python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 httplib2 将请求 POST 到服务器。对于文件上传(分段请求),您应该使用 Poster。
您可能需要先获取表单,然后才能将其发布到您的服务器检查安全令牌(隐藏字段或 cookie)
You can use httplib2 to POST requests to a server. For file uploading (multipart requests) you should use Poster.
You might need to GET the form before you can POST it your server checks for security tokens (hidden fields or cookies)