Python 中使用 POST 方法传递信息
POST 方法是一种通常更可靠的向 CGI 程序传递信息的方法。它以完全相同的方式打包信息,但不会在 URL 中的 ?后面作为文本字符串发送,而是作为一个单独的消息发送。此消息以标准输入的形式进入 CGI 脚本。
示例
以下为可以处理 GET 和 POST 方法的相同 hello_get.py 脚本。
#!/usr/bin/python
Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello %s %s</h2>" % (first_name, last_name)
print "</body>"
print "</html>"输出
让我们再次采用与上述相同的示例,它使用 HTML FORM 和提交按钮传递两个值。我们使用相同的 CGI 脚本 hello_get.py 来处理此输入。
<form action = "/cgi-bin/hello_get.py" method = "post"> First Name: <input type = "text" name = "first_name"><br /> Last Name: <input type = "text" name = "last_name" /> <input type = "submit" value = "Submit" /> </form>
以下是上述表单的实际输出。输入名字和姓氏,然后单击提交按钮以查看结果。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP