Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

simplest httpserver with python (See related posts)

responding "hello" at http://localhost:8080
   1  
   2  from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
   3  
   4  class MyServer(BaseHTTPRequestHandler):
   5      def do_GET(self):
   6          self.send_response(200, 'OK')
   7          self.send_header('Content-type', 'text/html')
   8          self.end_headers()
   9          self.wfile.write( "hello" )
  10  
  11      @staticmethod
  12      def serve_forever(port):
  13          HTTPServer(('', port), MyServer).serve_forever()
  14  
  15  if __name__ == "__main__":
  16      MyServer.serve_forever(8080)

You need to create an account or log in to post comments to this site.


Click here to browse all 5551 code snippets

Related Posts