Skip to content

Instantly share code, notes, and snippets.

@jishnu7
Created May 31, 2012 06:29
Show Gist options
  • Save jishnu7/2841491 to your computer and use it in GitHub Desktop.
Save jishnu7/2841491 to your computer and use it in GitHub Desktop.
Python web server
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class ServerHandler(BaseHTTPRequestHandler):
def do_GET(self):
print "GET :",self.path
# Send success response
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Return Data
self.wfile.write("Hurray!! You tried to access "+self.path)
def do_POST(self):
print "POST :",self.path
# Send success response
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Return Data
self.wfile.write("Hurray!! You tried to access "+self.path)
def main():
try:
server = HTTPServer(('', 8000), ServerHandler)
print 'httpserver started.'
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