Nazymko

Untitled

May 6th, 2015
239
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import BaseHTTPServer
  3.  
  4.  
  5. HOST_NAME = 'localhost' # !!!REMEMBER TO CHANGE THIS!!!
  6. PORT_NUMBER = 9999 # Maybe set this to 9000.
  7.  
  8.  
  9. class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  10.     def do_HEAD(s):
  11.         s.send_response(200)
  12.         s.send_header("Content-type", "text/html")
  13.         s.end_headers()
  14.     def do_GET(s):
  15.         """Respond to a GET request."""
  16.         s.send_response(200)
  17.         s.send_header("Content-type", "text/html")
  18.         s.end_headers()
  19.         s.wfile.write("<html><head><title>Title goes here.</title></head>")
  20.         s.wfile.write("<body><p>This is a test.</p>")
  21.         # If someone went to "http://something.somewhere.net/foo/bar/",
  22.         # then s.path equals "/foo/bar/".
  23.         s.wfile.write("<p>You accessed path: %s</p>" % s.path)
  24.         s.wfile.write("</body></html>")
  25.  
  26. if __name__ == '__main__':
  27.     server_class = BaseHTTPServer.HTTPServer
  28.     httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
  29.     print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
  30.     try:
  31.         httpd.serve_forever()
  32.     except KeyboardInterrupt:
  33.         pass
  34.     httpd.server_close()
  35.     print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
RAW Paste Data