metallica_1860 发表于 2013-1-15 02:24:17

python是个什么东西---python---python的httpsever

# -*- coding:UTF-8 -*-import osimport BaseHTTPServerimport timeimport threadingimport urlparseclass ServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):#    def __init__(self,request, client_address, server):#      BaseHTTPServer.BaseHTTPRequestHandler.__init__(self,request, client_address, server)#      self.server = server      #处理用户的GET请求    def do_GET(self):      try:            str = urlparse.urlparse(self.path)            fn = self.path            print "address_string : " + self.address_string()            print "path : " + fn            print "query : " + str.query            #写回客户端            self.wfile.write("111")      except:            print u'出现异常'            self.send_error(404, 'File Not Found:%s' % fn)    class Server:    def startServer(self):      server_address = ('', 8080)      httpd = BaseHTTPServer.HTTPServer(server_address, ServerHandler)      server_thread = threading.Thread(target=httpd.serve_forever)      server_thread.setDaemon(True)      server_thread.start()      class HttpStart:    def start(self):      server = Server()      server.startServer()      starttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))          print u'%s 服务器已启动' % starttime
页: [1]
查看完整版本: python是个什么东西---python---python的httpsever