用Python創建最簡單的web服務器

用Python創建最簡單的web服務器

$ python -m SimpleHTTPServer 8080

支持開發功能的 基礎web

from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class TestHTTPHandle(BaseHTTPRequestHandler):
    def do_GET(self):
        buf = '''
              <html>
                  <head><title>Not Found</title> </head>
                  <body> The requested document '%s' was not found.  </body>
              </html>
              '''
        self.protocal_version = "HTTP/1.1"
        self.send_response(200)
        self.send_header("Welcome", "Contect")
        self.end_headers()
        self.wfile.write(buf)

def start_server():
    http_server = HTTPServer(('0.0.0.0', 8080), TestHTTPHandle)
    http_server.serve_forever()

start_server()
相關文章
相關標籤/搜索