import requests import json from datetime import datetime # 设置请求头 headers = { "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMCIsImV4cCI6MTc2NjI5ODM5Mn0.X6SBI8Kizrr_2KYvm4YVm0sCQIDB0BJ8MH_BNmoRxqM", "Content-Type": "application/json" } # 设置请求体 data = { "title": f"测试宝箱 {datetime.now().strftime('%H:%M:%S')}", "option_a": "选项A", "option_b": "选项B", "countdown_seconds": 60 # 1分钟倒计时 } # 发送POST请求 try: response = requests.post("http://localhost:8000/api/chests", headers=headers, data=json.dumps(data)) print(f"Status Code: {response.status_code}") print(f"Response: {response.text}") if response.status_code == 200: chest = response.json() print(f"Created chest: ID={chest['id']}, Title={chest['title']}, Created At={chest['created_at']}") except Exception as e: print(f"Error: {e}")