Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:44:30+00:00 2026-06-06T22:44:30+00:00

I`m trying to send simple html page with form data to user with GET,

  • 0

I`m trying to send simple html page with form data to user with GET, and then receive variables from form with POST.
HTML file looks like:

<HTML>
<title> My Title</title>
<body>
<form  method="post" action="http.py">
<input name="Name" type="text"/>
<input name="Submit" type="submit" value="Submit" />
</form>
</body>
</HTML>

Here is python script:

import os
import cgi
import sys
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler



class customHTTPServer(BaseHTTPRequestHandler):
        def do_GET(self):
                self.send_response(200)
                self.send_header('Content-type', 'text/html')
                self.end_headers()
                fh=open('index.html','r')
                self.wfile.write(fh.read())
                return

        def do_POST(self):
            form = cgi.FieldStorage()
            self.send_response(200)
            self.end_headers()
            self.wfile.write(form['Name'].value)


def main():
       try:
            server = HTTPServer(('',9111),customHTTPServer)
            print 'server started at port 8080'
            server.serve_forever()
       except KeyboardInterrupt:
            server.socket.close()

if __name__=='__main__':
       sys.exit(main())

But FieldStorage remains empty all the time. I already tried to check what is in self.rfile, and found that if i try to do self.rfile.readlines() , browser stuck and looks like script is waiting for the end of data stream. From where i should take Name variable that i`m submitting with POST?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:44:31+00:00Added an answer on June 6, 2026 at 10:44 pm

    I think you might be mixing some concepts here. You have both the idea of a server and also a cgi script. No matter what your POST action is (http.py or whatever), your server is just going to take in a request. No CGI processing is actually happening. So you can first adjust your html template to this for simplicity:

    <form  method="post" action="">
    

    Then, you should reference this other question about how to read from the request, as opposed to trying to use the cgi fieldstorage:

    import urlparse
    
    ...
    
        def do_POST(self):
            length = int(self.headers.getheader('content-length'))
            postvars = urlparse.parse_qs(self.rfile.read(length), keep_blank_values=1)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(postvars)
    

    The issue you were having, and because this is a very low level way to create a web server app, if you read indefinitely from the input stream, it will keep going and block. You check the header for the content length and only read that many bytes. You don’t have any need for the cgi module at all, because this is not a cgi script.

    A cgi script works by the server seeing the request is for a file of a matching type and location, and executing it in a subprocess like a normal program. It feeds the process the args and then gets back a response to ship back to the client. If this were a cgi script, the server would be in one module, running forever, and the cgi code would be in another with much simpler code to check the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do a simple AJAX function to send data from query
I'm trying to post some very simple data to a php file using jquery
I am trying to send data from PHP to a bash script and then
I am trying to send a simple string from One viewcontroller to another viewcontroller
I am trying to make a simple application which will send the user to
I'm trying to build a simple user authorization system where a .txt file stores
Im trying to build a simple AJAX script that uses a form to send
i am trying to send a variable to another page with a post request
Using $.getJSON(); or $.post(); I'm trying to send some parameters through a page that
I'm trying to send a multi-line post from an iPhone/iPad to a php service,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.