Created
May 31, 2012 06:29
-
-
Save jishnu7/2841491 to your computer and use it in GitHub Desktop.
Python web server
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
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