Created
March 2, 2011 03:53
-
-
Save seungjin/850443 to your computer and use it in GitHub Desktop.
post debugger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string,cgi,time | |
from os import curdir, sep | |
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
#import pri | |
class MyHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
print "do_GET" | |
self.send_response(200) | |
self.send_header('Content-type', 'text/html') | |
self.end_headers() | |
self.wfile.write("hello world") | |
def do_POST(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/html') | |
self.end_headers() | |
self.wfile.write("hello world") | |
print "do_POST" | |
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) | |
if ctype == 'multipart/form-data': | |
postvars = cgi.parse_multipart(self.rfile, pdict) | |
elif ctype == 'application/x-www-form-urlencoded': | |
length = int(self.headers.getheader('content-length')) | |
postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1) | |
else: | |
postvars = {} | |
print postvars | |
def main(): | |
try: | |
server = HTTPServer(('', 8080), MyHandler) | |
print 'started httpserver...' | |
server.serve_forever() | |
except KeyboardInterrupt: | |
print '^C received, shutting down server' | |
server.socket.close() | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment