zoukankan      html  css  js  c++  java
  • 3.在url中传递参数(其实与requests模块使用大致相同)

    3.在url中传递参数(其实与requests模块使用大致相同)
    
    node2:/root/python/20200525#cat t500.py 
    import asyncio,aiohttp
    
    async def fetch_async(url,params):
        async with aiohttp.ClientSession() as session:
            async with session.get(url,params=params) as r:
                print(dir(r))
                print(r.url)
                print(await r.text())
    data1={'a': '111', 'b': '111'}
    data2={'a': '222', 'b': '222'}
    data3={'a': '333', 'b': '333'}
    tasks = [fetch_async('http://192.168.137.3:9000/test111/',data1), fetch_async('http://192.168.137.3:9000/test222/',data2),fetch_async('http://192.168.137.3:9000/test333/',data3)]
    
    event_loop = asyncio.get_event_loop()
    results = event_loop.run_until_complete(asyncio.gather(*tasks))
    event_loop.close()
    
    #@require_http_methods(["POST"])
    def test111(req):
        time.sleep(5)
        a=req.GET['a']
        b=req.GET['b']
        print a
        print b
        return HttpResponse(str(a))
    #@require_http_methods(["POST"])
    def test222(req):
        time.sleep(6)
        a=req.GET['a']
        print a
        b=req.GET['b']
        print b
        return HttpResponse(str(a))
    #@require_http_methods(["POST"])
    def test333(req):
        time.sleep(7)
        a=req.GET['a']
        print a
        return HttpResponse(str(a))
    #@require_http_methods(["POST"])
    def test444(req):
        time.sleep(8)
        a=req.GET['a']
        print a
        return HttpResponse(str(a))
    	
  • 相关阅读:
    全栈必备Linux 基础
    Linux 的 Socket IO 模型
    Vim
    Linux 下使用 Sar 简介
    提高效率,推荐 5 款命令行工具
    Vim小技巧
    剑指Offer 矩形覆盖
    剑指Offer 变态跳台阶
    剑指Offer 跳台阶
    2016 网易校招内推C/C++第二场8.6
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348355.html
Copyright © 2011-2022 走看看