Network Python Tutorial

import os, sys
import BaseHTTPServer, cgi
servAddr = ('',80)
class httpServHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_POST(self):
        self.query_string = self.rfile.read( int(self.headers['Content-Length']))
        self.args = dict(cgi.parse_qsl(self.query_string))
        self.send_response(200)
        self.send_header('Content-type','text/html')
        self.end_headers()
        sys.stdout = self.wfile
        self.wfile.write("

Handling Post

")
        self.wfile.write("

  • Location: %s"%(self.path))
            self.wfile.write("
  • Arguments: %s
    "%(self.args))
            execfile(self.path, self.args)
    os.chdir('/myTest')
    serv = BaseHTTPServer.HTTPServer( servAddr, httpServHandler)
    serv.serve_forever()