explore_api_endpoints.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import requests
  2. import json
  3. def explore_api_endpoints():
  4. """探索服务器上可用的API端点"""
  5. base_url = "http://192.168.3.143:5500"
  6. # 常见的API路径模式
  7. possible_paths = [
  8. "/",
  9. "/api",
  10. "/api/",
  11. "/api/data-parse",
  12. "/api/data-parse/",
  13. "/health",
  14. "/status",
  15. "/docs",
  16. "/swagger",
  17. "/openapi",
  18. "/process-urls",
  19. "/api/process-urls",
  20. "/data-parse/process-urls",
  21. "/api/data-parse/process-urls"
  22. ]
  23. print(f"正在探索服务器: {base_url}")
  24. print("=" * 60)
  25. for path in possible_paths:
  26. url = base_url + path
  27. try:
  28. print(f"\n🔍 测试路径: {path}")
  29. # 尝试GET请求
  30. try:
  31. response = requests.get(url, timeout=10)
  32. print(f" GET {path} -> 状态码: {response.status_code}")
  33. if response.status_code == 200:
  34. print(f" 响应内容: {response.text[:200]}...")
  35. except Exception as e:
  36. print(f" GET {path} -> 错误: {e}")
  37. # 尝试POST请求(对于process-urls接口)
  38. if "process-urls" in path:
  39. try:
  40. test_data = {"urlArr": ["https://example.com"]}
  41. response = requests.post(
  42. url,
  43. json=test_data,
  44. headers={"Content-Type": "application/json"},
  45. timeout=10
  46. )
  47. print(f" POST {path} -> 状态码: {response.status_code}")
  48. if response.status_code != 404:
  49. print(f" 响应内容: {response.text[:200]}...")
  50. except Exception as e:
  51. print(f" POST {path} -> 错误: {e}")
  52. except Exception as e:
  53. print(f" ❌ 测试失败: {e}")
  54. print("\n" + "=" * 60)
  55. print("探索完成!")
  56. if __name__ == "__main__":
  57. explore_api_endpoints()