blob: bf05b56d2990d49802d0ee75cfee03490769e07f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
from typing import Optional
from aiohttp import ClientSession
async def get_text(url: str, headers: Optional[dict] = None) -> str:
"""异步以 Get 方式请求 url"""
async with ClientSession() as session:
async with session.get(url, headers=headers) as r:
result = await r.text()
return result
async def get_bytes(url: str, headers: Optional[dict] = None) -> bytes:
"""异步以 Get 方式请求 url"""
async with ClientSession() as session:
async with session.get(url, headers=headers) as r:
result = await r.read()
return result
async def post_bytes(url: str, params: Optional[dict] = None) -> bytes:
"""异步以 Post 方式请求 url"""
async with ClientSession() as session:
async with session.post(url, params=params) as r:
result = await r.read()
return result
|