Skip to content

Instantly share code, notes, and snippets.

@pavgup
Created April 23, 2014 15:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pavgup/11220737 to your computer and use it in GitHub Desktop.
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.
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