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))
	

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章