soarli

一个轻量的Python HTTP服务
以共享目录 /home/haoel IP地址192.168.1.1为例:$ cd /home/haoel $ py...
扫描右侧二维码阅读全文
10
2020/06

一个轻量的Python HTTP服务

以共享目录 /home/haoel IP地址192.168.1.1为例:

$ cd /home/haoel
$ python -m SimpleHTTPServer 3000

若开启失败:

python -m http.server 3000

只让这个HTTP服务器服务于本地环境:

import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass  = BaseHTTPServer.HTTPServer
Protocol     = "HTTP/1.0"
 
if sys.argv[1:]:
    port = int(sys.argv[1])
else:
    port = 8000
server_address = ('127.0.0.1', port)
 
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
 
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()

参考资料:

coolshell.cn/articles/1480.html

最后修改:2021 年 12 月 02 日 08 : 07 PM

发表评论