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。我需要一种方法来管理请求的两种“类型”(使用两个库?),如果这是可行的话。提前谢谢。
答案 0 :(得分:0)
尝试这样的事情:
import BaseHTTPServer
import CGIHTTPServer
server = BaseHTTPServer.HTTPServer
server_address = ("", 8888)
class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):
def do_GET(self):
#do something
def do_POST(self):
#do something
httpd = server(server_address, MyHandler)
httpd.serve_forever()