Created
April 23, 2014 15:47
-
-
Save pavgup/11220737 to your computer and use it in GitHub Desktop.
This stands up a python http server and receives both POST and GET requests and prints to the console the parameters and values it receives over HTTP. This runs on port 9000 and binds 0.0.0.0, so be careful about firewall settings when testing this.
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
import BaseHTTPServer | |
import urlparse | |
class SimpleHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
if "?" in self.path: | |
for key,value in dict(urlparse.parse_qsl(self.path.split("?")[1], True)).items(): | |
print key + " = " + value | |
def do_POST(self): | |
self.send_response(200) | |
if self.rfile: | |
# print urlparse.parse_qs(self.rfile.read(int(self.headers['Content-Length']))) | |
for key,value in dict(urlparse.parse_qs(self.rfile.read(int(self.headers['Content-Length'])))).items(): | |
print key + " = " + value[0] | |
def log_request(self, code=None, size=None): | |
return | |
if __name__ == "__main__": | |
try: | |
BaseHTTPServer.HTTPServer(("0.0.0.0", 9000), SimpleHandler).serve_forever() | |
except KeyboardInterrupt: | |
print('shutting down server') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment