一、Python3 搭建简易HTTP服务器

python -m http.server

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

Python实现简易HTTP服务器

Python3 cgiserver

python -m http.server --cgi 8080

Python实现简易HTTP服务器

 

二、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

相关文章:

  • 2021-09-15
  • 2021-12-17
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2021-12-15
  • 2022-01-06
猜你喜欢
  • 2021-08-12
  • 2021-08-27
  • 2022-12-23
  • 2021-08-07
  • 2021-12-28
  • 2021-06-13
相关资源
相似解决方案