58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""
|
|
测试 client.dial 功能
|
|
"""
|
|
|
|
import asyncio
|
|
from pkg.dial import client
|
|
|
|
|
|
async def test_dial():
|
|
"""测试 client.dial 的基本功能"""
|
|
print("=== 测试 client.dial ===")
|
|
|
|
try:
|
|
# 测试 GET 请求到 httpbin.org
|
|
print("测试 GET 请求...")
|
|
response = await client.dial("https://httpbin.org/get")
|
|
print(f"状态码: {response.status_code}")
|
|
print(f"响应头: {dict(response.headers)}")
|
|
data = response.json()
|
|
print(f"响应数据: {data.get('url', 'N/A')}")
|
|
print()
|
|
|
|
# 测试 POST 请求
|
|
print("测试 POST 请求...")
|
|
response = await client.dial(
|
|
url="https://httpbin.org/post",
|
|
method="POST",
|
|
headers={"Content-Type": "application/json"},
|
|
body={"test": "data", "message": "Hello, World!"},
|
|
)
|
|
print(f"状态码: {response.status_code}")
|
|
data = response.json()
|
|
print(f"响应数据: {data.get('json', 'N/A')}")
|
|
print()
|
|
|
|
# 测试带查询参数的请求
|
|
print("测试带查询参数的请求...")
|
|
response = await client.dial(
|
|
url="https://httpbin.org/get",
|
|
params={"param1": "value1", "param2": "value2"},
|
|
)
|
|
print(f"状态码: {response.status_code}")
|
|
data = response.json()
|
|
print(f"查询参数: {data.get('args', 'N/A')}")
|
|
print()
|
|
|
|
print("✅ 所有测试通过!")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 测试失败: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_dial())
|