- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Passing Information Using POST Method in Python
A generally more reliable method of passing information to a CGI program is the POST method. This packages the information in exactly the same way as GET methods, but instead of sending it as a text string after a ? in the URL it sends it as a separate message. This message comes into the CGI script in the form of the standard input.
Example
Below is same hello_get.py script which handles GET as well as POST method.
#!/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>"
Output
Let us take again same example as above which passes two values using HTML FORM and submit button. We use same CGI script hello_get.py to handle this input.
<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>
Here is the actual output of the above form. You enter First and Last Name and then click submit button to see the result.
- Related Articles
- Passing Information using GET method in Python
- GET and POST requests using Python Programming
- How to read form data using JSP via POST Method?
- Using POST Methods in Perl
- Difference Between GET and POST Method in HTML
- Resource Usage Information using Python
- Passing to method geticon in SAPUI5
- Passing array to method in Java
- Using post request in middleware in express
- Python Program to Implement Depth First Search Traversal using Post Order
- Passing empty parameter to a method in JavaScript
- How to use POST method to send data in jQuery Ajax?
- What is difference between GET and POST method in HTTP protocol?
- Post favourite stuffs using pixelpumper on mac
- How to get service information with the WMI method using PowerShell?

Advertisements