python3 异步GET、POST请求
程序员文章站
2022-04-02 11:05:52
1、GET请求import asyncioimport websocketsimport jsonfrom aiohttp import ClientSessionimport urllib.parseimport argparseasync def test_req(): await asyncio.sleep(1) async with ClientSession() as session: params = urllib.parse.urlencod...
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
上一篇: 【Python】读写xlsx 文件
下一篇: py
推荐阅读
-
php中GET和POST请求发送几种方法总结
-
HTML中Get请求和Post请求的区别_html/css_WEB-ITnose
-
Ajax相关——get请求和post请求的区别
-
php发送get、post请求的几种方法,getpost_PHP教程
-
无论GET还是POST都可以用通用方式获取请求参数
-
PHP中使用cURL实现Get和Post请求的方法
-
php 利用socket发送HTTP请求(GET,POST),socketget_PHP教程
-
PHP模拟发送POST请求之三、加强file_get_contents发送POST请求
-
post请求重定向到get请求问题
-
php自定义类fsocket模拟post或get请求的方法_PHP