“编译修改”
This commit is contained in:
1 parent
69e4b08946
commit
e79bf5a26c
224 files changed
+66161
-6
No files matched your search
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
使用浏览器Token测试OSS文件下载接口
|
||||
请从浏览器开发者工具中复制Token
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
# 配置
|
||||
BASE_URL = "http://localhost:8080"
|
||||
CLIENT_ID = "e5cd7e4891bf95d1d19206ce24a7b32e"
|
||||
|
||||
# 测试的OSS ID
|
||||
TEST_OSS_IDS = [
|
||||
1976838445737193474, # 2.png
|
||||
1976861922200408066 # PDF文件
|
||||
]
|
||||
|
||||
def test_oss_download(token, oss_id):
|
||||
"""测试OSS下载接口"""
|
||||
url = f"{BASE_URL}/resource/oss/download/{oss_id}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"clientid": CLIENT_ID,
|
||||
"referer": "http://localhost"
|
||||
}
|
||||
|
||||
print(f"\n📥 测试下载 OSS ID: {oss_id}")
|
||||
print(f"URL: {url}")
|
||||
|
||||
try:
|
||||
response = requests.get(url, headers=headers, timeout=30, stream=True)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"Content-Type: {response.headers.get('Content-Type')}")
|
||||
print(f"Content-Disposition: {response.headers.get('Content-Disposition')}")
|
||||
print(f"Content-Length: {response.headers.get('Content-Length')}")
|
||||
|
||||
if response.status_code == 200:
|
||||
content_length = len(response.content)
|
||||
print(f"✅ 下载成功!文件大小: {content_length} bytes")
|
||||
return True
|
||||
elif response.status_code == 403:
|
||||
print(f"❌ 403 Forbidden - 权限不足")
|
||||
print(f"响应内容: {response.text}")
|
||||
return False
|
||||
elif response.status_code == 404:
|
||||
print(f"❌ 404 Not Found - 文件不存在")
|
||||
print(f"响应内容: {response.text}")
|
||||
return False
|
||||
else:
|
||||
print(f"❌ 下载失败 ({response.status_code})")
|
||||
print(f"响应内容: {response.text[:500]}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ 下载异常: {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("OSS文件下载测试(使用浏览器Token)")
|
||||
print("=" * 60)
|
||||
print("\n请从浏览器开发者工具中复制Token(不包含Bearer前缀):")
|
||||
print("1. 按F12打开开发者工具")
|
||||
print("2. 进入Application/应用 -> Local Storage")
|
||||
print("3. 找到 Admin-Token,复制其值")
|
||||
print()
|
||||
|
||||
token = input("请输入Token: ").strip()
|
||||
|
||||
if not token:
|
||||
print("❌ Token不能为空")
|
||||
return
|
||||
|
||||
# 测试两个文件
|
||||
for oss_id in TEST_OSS_IDS:
|
||||
test_oss_download(token, oss_id)
|
||||
print("-" * 60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in new issue
Block a user