45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
|
|
#!/usr/bin/env python
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
检查请求头
|
||
|
|
"""
|
||
|
|
|
||
|
|
import requests
|
||
|
|
|
||
|
|
def check_headers():
|
||
|
|
"""检查请求头"""
|
||
|
|
# 创建会话
|
||
|
|
session = requests.Session()
|
||
|
|
|
||
|
|
# 先登录
|
||
|
|
print("=== 检查请求头 ===")
|
||
|
|
login_data = {
|
||
|
|
"username": "admin",
|
||
|
|
"password": "admin123"
|
||
|
|
}
|
||
|
|
|
||
|
|
# 尝试不同的请求头
|
||
|
|
headers_list = [
|
||
|
|
{"X-Requested-With": "XMLHttpRequest"},
|
||
|
|
{"x-requested-with": "XMLHttpRequest"},
|
||
|
|
{"X-Requested-With": "xmlhttprequest"},
|
||
|
|
]
|
||
|
|
|
||
|
|
for i, headers in enumerate(headers_list, 1):
|
||
|
|
print(f"\n--- 测试请求头 {i}: {headers} ---")
|
||
|
|
|
||
|
|
login_response = session.post("http://127.0.0.1:5000/login", data=login_data, headers=headers)
|
||
|
|
print(f"响应状态码: {login_response.status_code}")
|
||
|
|
print(f"响应内容类型: {login_response.headers.get('content-type', 'unknown')}")
|
||
|
|
|
||
|
|
if 'json' in login_response.headers.get('content-type', '').lower():
|
||
|
|
try:
|
||
|
|
login_json = login_response.json()
|
||
|
|
print(f"响应JSON: {login_json}")
|
||
|
|
except:
|
||
|
|
print("JSON解析失败")
|
||
|
|
else:
|
||
|
|
print("响应不是JSON格式")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
check_headers()
|