kboss/kgadget/src/async_container.py
2025-07-16 14:27:17 +08:00

24 lines
871 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import aiohttp
import asyncio
import ssl
async def async_post(url, headers=None, data=None, timeout=1.5, verify=False):
# 安全警告verify=False 会跳过 SSL 验证,仅用于测试环境!
ssl_context = None
if not verify:
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
# 创建 connector 替代直接使用 ssl 参数
connector = aiohttp.TCPConnector(ssl=ssl_context)
async with aiohttp.ClientSession(connector=connector) as session:
async with session.post(url, headers=headers, data=data, timeout=timeout) as response:
content = await response.text()
return {
"status_code": response.status,
"headers": dict(response.headers),
"content": content
}