欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python3 异步GET、POST请求

程序员文章站 2022-06-26 17:13:50
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