58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
|
|
import requests
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
# 配置
|
|||
|
|
BASE_URL = "http://localhost:8080"
|
|||
|
|
LOGIN_URL = f"{BASE_URL}/login/test"
|
|||
|
|
|
|||
|
|
# 登录获取token
|
|||
|
|
print("登录系统...")
|
|||
|
|
login_data = {
|
|||
|
|
"username": "admin",
|
|||
|
|
"password": "admin123"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
response = requests.post(LOGIN_URL, json=login_data)
|
|||
|
|
token = response.json().get("token")
|
|||
|
|
|
|||
|
|
# 测试不同的导入方式
|
|||
|
|
headers = {'Authorization': f'Bearer {token}'}
|
|||
|
|
|
|||
|
|
print("\n测试1: 直接POST请求(无文件)")
|
|||
|
|
response = requests.post(
|
|||
|
|
f"{BASE_URL}/dpc/intermediary/importPersonData",
|
|||
|
|
headers=headers
|
|||
|
|
)
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应: {response.text[:200]}")
|
|||
|
|
|
|||
|
|
print("\n测试2: 带文件的POST请求(URL参数)")
|
|||
|
|
files = {
|
|||
|
|
'file': ('test.xlsx', open('doc/个人中介黑名单测试数据_1000条.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|||
|
|
}
|
|||
|
|
response = requests.post(
|
|||
|
|
f"{BASE_URL}/dpc/intermediary/importPersonData?updateSupport=false",
|
|||
|
|
files=files,
|
|||
|
|
headers=headers
|
|||
|
|
)
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应: {response.text[:500]}")
|
|||
|
|
files['file'][1].close()
|
|||
|
|
|
|||
|
|
print("\n测试3: 带文件的POST请求(Form数据)")
|
|||
|
|
files = {
|
|||
|
|
'file': ('test.xlsx', open('doc/个人中介黑名单测试数据_1000条.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|||
|
|
}
|
|||
|
|
data = {
|
|||
|
|
'updateSupport': 'false'
|
|||
|
|
}
|
|||
|
|
response = requests.post(
|
|||
|
|
f"{BASE_URL}/dpc/intermediary/importPersonData",
|
|||
|
|
files=files,
|
|||
|
|
data=data,
|
|||
|
|
headers=headers
|
|||
|
|
)
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应: {response.text[:500]}")
|
|||
|
|
files['file'][1].close()
|