1、GET请求
import asyncio
import websockets
import json
from aiohttp import ClientSession
import urllib.parse
import argparse
async def test_req():
await asyncio.sleep(1)
async with ClientSession() as session:
params = urllib.parse.urlencode({"addr": resp_node, "entity": resp_entity, "whoami": "tester", "overtime": 3})
url = req_url + "?%s" % params
print("REQ:", url)
async with session.get(url) as response:
response = await response.read()
print("RESP:", response)
2、POST请求
async def send_data():
params = {"a":"b"}
async with ClientSession() as session:
# 发送topic测试数据
header = {"Content-Type": "application/json;charset=UTF-8"}
async with session.post(writeCurveUrl + "/",
data=params, headers=header) as response:
response = await response.read()
print(response.decode())
本文地址:https://blog.csdn.net/wudiansheng/article/details/110917022
黄山市民网:https://www.huangshanshimin.com/