今天花了一點時間來看看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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.