【发布时间】:2011-11-18 18:04:10
【问题描述】:
class WebServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):
# Works with basehttphandler
do_get(self):
if 'home' in self.path:
<do something here>
# "Working" Method is commented out. The problem I'm having is being unable to
# handle requests like GET, POST, etc with CGIHTTPRequestHandler.:
#
#DoIT=BaseHTTPServer.BaseHTTPRequestHandler((SERVER_ADDRESS,PORT),WebServer)
DoIt=webserver((SERVER_ADDRESS,PORT),CGIHTTPServer.CGIHTTPRequestHandler)
DoIT.serve_forever()
这适用于 basehttprequesthandler,不适用于 cgihttprequesthandler。如果可行的话,我需要一种方法来管理请求的两种“类型”(使用两个库?)。提前致谢。
【问题讨论】:
-
当某些事情不起作用时,请尝试提供一些细节。您收到错误消息吗?它没有做你期望的事情吗?
-
基本上我要做的是管理 GET 请求和其他 HTTP 请求方法。使用 BaseHTTPServer,“do_GET(self)”有效。一旦我使用不再是一个选项的 CGIHTTPRequestHandler 。我没有收到任何错误,它只是停止工作。由于我需要能够使用 cgi,因此仅使用 basehttpserver 不是项目可扩展的。基本上,我需要能够使用 CGIHTTPServer 处理“do_GET(self)”类型的函数。很抱歉有任何混淆。我不太擅长解释。
标签: python basehttprequesthandler cgihttprequesthandler