Created
September 24, 2014 22:04
-
-
Save kylemcdonald/4cbd136189d0b177cbbb to your computer and use it in GitHub Desktop.
Shows anything sent over POST.
This file contains 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
#!/usr/bin/python | |
import time | |
import BaseHTTPServer | |
import cgi | |
from pprint import pprint | |
HOST_NAME = 'localhost' | |
PORT_NUMBER = 9000 | |
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_POST(self): | |
form = cgi.FieldStorage( | |
fp=self.rfile, | |
headers=self.headers, | |
environ={"REQUEST_METHOD": "POST"} | |
) | |
for item in form.list: | |
print "%s=%s" % (item.name, item.value) | |
if __name__ == '__main__': | |
server_class = BaseHTTPServer.HTTPServer | |
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler) | |
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass | |
httpd.server_close() | |
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment