zoukankan      html  css  js  c++  java
  • BaseHTTPServer.HTTPServer 如何停止

    BaseHTTPServer.HTTPServer是python中一个很好用的够简单的http服务器的库,但是它的stop_server方法是空的,所以开始用的时候老是不知道怎么才能关掉它,了解后终于找到了方法,备忘一下:

       
    class HttpServer(BaseHTTPServer.HTTPServer):
            
        def serve_forever(self):
            self.stopped = False                    
            """Handle one request at a time until doomsday."""
            while not self.stopped:
                self.handle_request()
        def (self):
            self.stopped = True
            conn = httplib.HTTPConnection("localhost:%d" % 8080)
            conn.request("QUIT", "/")

    class InfocServerHandler(SimpleHTTPRequestHandler):   
        def do_GET(self):
            scm, netloc, path, params, query, fragment = urlparse.urlparse(self.path, 'http')   
            self.wfile.write('HTTP/1.1 200 OK\r\n')
            self.send_header('Content-Length',len(dat))
            self.send_header('Cache-Control','max-age=1')
            self.send_header('Content-Type','application/x-shockwave-flash')
            self.end_headers()
            self.wfile.write(dat)
      
       

     


    作者:GangWang
    出处:http://www.cnblogs.com/GnagWang/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

     
  • 相关阅读:
    HttpWatch 有火狐版本?
    JQgrid的最新API
    jqgrid
    JSON的学习网站
    array创建数组
    Numpy安装及测试
    SQLite3删除数据_7
    SQLite3修改数据_6
    SQLite3查询一条数据_5
    SQLite3查询所有数据_4
  • 原文地址:https://www.cnblogs.com/GnagWang/p/1756634.html
Copyright © 2011-2022 走看看