今天花了一点时间来看看SimpleHTTPServer。 看这个的原因是想架一个简单简单简单简单的Http Server,实现这样的功能: 本来这个功能是想用Karrigell来实现,但是有简单的方法,就简单一点。 介绍如下:(原文为英文,这里译成中文) Simple HTTP Server. 简单的HTTP服务器。(译注:如名所示) This module builds on BaseHTTPServer by implementing the standard GET and HEAD requests in a fairly straightforward manner. 我看到了其中的一个类:class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler), Simple HTTP request handler with GET and HEAD commands. This serves files from the current directory and any of its subdirectories. The GET and HEAD requests are identical except that the HEAD request omits the actual contents of the file. 我们来试一下: Hello World! 保存为:index.html 02、创建一个Python程序,源码如下: import SimpleHTTPServer 保存为:test.py 03、在命令提示符下输入:python test.py,回车, 此时在命令提示符下可以看到:otherrrr - - [10/Jan/2008 16:23:58] "GET / HTTP/1.1" 200 - 04、最后提醒一句:使用Ctrl+Break关闭。 (本文所涉及环境:Windows2003/Python2.5) |
Python的SimpleHTTPServer
最新推荐文章于 2024-02-09 08:00:00 发布