일반적으로 CGI 프로그램에 정보를 전달하는 보다 안정적인 방법은 POST 방법입니다. 이것은 GET 메소드와 정확히 같은 방식으로 정보를 패키징하지만, ? 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과 submit 버튼을 사용하여 두 개의 값을 전달하는 위와 같은 예를 다시 살펴보겠습니다. 이 입력을 처리하기 위해 동일한 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>
다음은 위 양식의 실제 출력입니다. 이름과 성을 입력하고 제출 버튼을 클릭하면 결과를 볼 수 있습니다.
