2012-10-08 28 views
5

今天我發現自己需要一個簡單的HTTP服務器,它可以記錄/打印出有關請求的所有信息,並用一些虛擬答覆(用於調試)進行響應。令人驚訝的是,我找不到任何閱讀使用工具 - 我錯過了什麼?是否有用於調試目的的現成HTTP服務器?

Python的SimpleHTTPServer模塊看起來很有希望,也許有一種真正快速的方法來轉儲整個請求使用它?

我需要它在本地運行。

+2

http://werkzeug.pocoo.org/ – reptilicus

回答

7

從谷歌的一些快速搜索它看起來最簡單的方法來做到這一點將subchacass SimpleHttpServer和記錄任何你想看到的。

looks是很容易

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): 

    def do_GET(self): 
     logging.error(self.headers) 
     # whatever else you would like to log here 
     SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) 

Handler = ServerHandler 

httpd = SocketServer.TCPServer(("", PORT), Handler) 

print "serving at port", PORT 
httpd.serve_forever() 

另外,你可以擁有任何你想要的「虛擬」的答覆你do_GETdo_POST回報。

+1

是否有一種通用方法用於所有類型的請求? –

+0

$/usr/bin/python3 -m http.server – AAAfarmclub

5
ruby -r sinatra -e "get('/') { puts params.inspect }" 

文檔:http://www.sinatrarb.com

Ruby是簡單,靈活,它可以讓你快速嘲笑任何答覆。

+0

- 使用ruby進行python問題 - Wat? –

相關問題