aiohttp
GitHub路径
https://github.com/aio-libs/aiohttp#client
安装
pip install --user aiohttp
demo
#-*-coding:utf-8-*-
#@author :vict
#@Time :2020-10-29 15:36
#@File :aiohttpserver
#@software :PyCharm
from aiohttp import web
from aiohttp_session import get_session
async def handle(request):
name = request.match_info.get(‘name‘, "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
async def post_handler(request):
sheader = str(request.headers)
print(sheader)
data = await request.read()
sBody = str(data, encoding=‘utf8‘)
print(sBody)
app = web.Application()
app.add_routes([web.get(‘/‘, handle),
web.get(‘/{name}‘, handle),
web.post(‘/monitorCollection/laneHeartbeat‘, post_handler),
web.post(‘/monitorCollection/trafficRecord‘, post_handler),
web.post(‘/monitorCollection/laneChargeVersion‘, post_handler),
web.post(‘/monitorCollection/laneHardwareInfo‘, post_handler),
web.post(‘/monitorCollection/appHeartbeat‘, post_handler),
web.post(‘/monitorCollection/warningUpload‘, post_handler),
web.post(‘/monitorCollection/laneDeviceInfoUpload‘, post_handler)])
if __name__ == ‘__main__‘:
web.run_app(app, host=‘127.0.0.1‘, port=8284)