Python搭建简易HTTP服务器

一、Python3 搭建简易HTTP服务器

python -m http.server

浏览器访问:http://localhost:8000

Python3 cgiserver

python -m http.server --cgi 8080

二、Python 2 搭建简易HTTP服务器

python -m Web服务器模块 [端口号,默认8000]

“Web服务器模块”有如下三种:
BaseHTTPServer: 提供基本的Web服务和处理器类,分别是HTTPServer和BaseHTTPRequestHandler。
SimpleHTTPServer: 包含执行GET和HEAD请求的SimpleHTTPRequestHandler类。
CGIHTTPServer: 包含处理POST请求和执行CGIHTTPRequestHandler类。

如:
python -m SimpleHTTPServer 8080

启动CGI服务命令是:
python -mCGIHTTPServer 8080

三、其它

在Python3中执行 python -m SimpleHTTPServer 8000 会报错误:

No module named SimpleHTTPServer

猜你喜欢

转载自www.cnblogs.com/v5captain/p/9544821.html