前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >利用python实现简单的http和ht

利用python实现简单的http和ht

作者头像
py3study
发布2020-01-06 14:40:27
6010
发布2020-01-06 14:40:27
举报
文章被收录于专栏:python3

http服务器代码:

代码语言:javascript
复制
#!/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服务器代码:

代码语言:javascript
复制
#!/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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档