Advertisement
mikhail_dvorkin

Python HTTP server

Feb 27th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from http.server import HTTPServer, SimpleHTTPRequestHandler
  2.  
  3. hostName = "localhost"
  4. hostPort = 3333
  5.  
  6. class MyHandler(SimpleHTTPRequestHandler):
  7.      def write(self, s):
  8.           self.wfile.write(bytes(s, "utf-8"))
  9.          
  10.      def do_GET(self):
  11.           global counter
  12.           counter += 1
  13.           self.send_response(200)
  14.           self.send_header("Content-type", "text/html")
  15.           self.end_headers()
  16.           self.write('<html><body><p>HELLO</p>')          
  17.           self.write('<p>' + self.path + '</p>')
  18.           self.write('<p>You are #' + str(counter) + '</p>')
  19.           self.write('</body></html>')  
  20.  
  21. counter = 0
  22. myServer = HTTPServer((hostName, hostPort), MyHandler)  
  23. myServer.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement