发布时间:2019-09-16 07:31:25编辑:auto阅读(2037)
http服务器代码:
#!/usr/bin/python3
#python version 3.7
import sys
from http import server
from http.server import SimpleHTTPRequestHandler
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
server_address = ('127.0.0.1', port)
httpd = server.HTTPServer(server_address, SimpleHTTPRequestHandler)
httpd.serve_forever()
https服务器代码:
#!/usr/bin/python3
#python version 3.7
from http import server
from http.server import SimpleHTTPRequestHandler
import socket
import ssl
import sys
if sys.argv[1:]:
port = int(sys.argv[1])
else :
port = 8000
server_address = ("127.0.0.1", port)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
#context.load_cert_chain("xxx.pem","xxx.key")#自己添加
httpd = server.HTTPServer(server_address,SimpleHTTPRequestHandler)
httpd.socket = context.wrap_socket(httpd.socket, server_side = True)
httpd.serve_forever()
参考:
https://blog.csdn.net/hjxzb/article/details/78107811
https://blog.csdn.net/linux_hacher/article/details/78753805
https://blog.csdn.net/u010103202/article/details/74002538
https://blog.csdn.net/zhongbeida_xue/article/details/52625710
上一篇: python中的条件判断语句
下一篇: 初学Python之一:Python的安装
47842
46390
37281
34733
29312
25973
24914
19950
19544
18030
5792°
6413°
5927°
5961°
7064°
5911°
5944°
6438°
6404°
7778°