您的位置:首页 > 编程语言 > Python开发

用Python建立最简单的web服务器

2016-06-22 00:00 861 查看
摘要: 用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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: