本代码运行后会减轻8088端口,用户访问:http://127.0.0.1:8088 或输出html代码:Hello World!
#!/usr/bin/python import BaseHTTPServer class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('Hello, world !') return print "Listening on port 8088..." server = BaseHTTPServer.HTTPServer(('', 8088), MyHandler) server.serve_forever()