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()
Turq is a small HTTP server that can be scripted in a Python-based
language. Use it to set up mock HTTP resources that respond with the
status, headers, and body of your choosing. Turq is designed for quick
interactive testing, but can be used in automated scenarios as well.
从google上的一些快速搜索来看,最简单的方法是subcass SimpleHttpServer并记录您想看到的任何内容。在
这很容易
另外,您可以让您的
do_GET
和do_POST
返回您想要的任何“伪”回复。在Turq在这种情况下效果很好。它是用Python编写的,使用简单,但又广泛、灵活,甚至有一个GUI。Turq的开发者这样描述它:
它还有good documentation。在
注意:虽然Turq非常有用,但是它的作者已经停止了对它的维护,而是建议使用mitmproxy;mitmproxy也有一个pythonapi。在
文档:http://www.sinatrarb.com
Ruby简单而灵活,它允许您快速地模仿任何回复。在
相关问题 更多 >
编程相关推荐