首页 > Web开发 > 详细

aiohttp

时间:2020-10-30 19:09:25      阅读:28      评论:0      收藏:0      [点我收藏+]

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)

aiohttp

原文:https://www.cnblogs.com/huanyinglvtuan/p/13903677.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!