fastapi-login/test_client.py
2024-01-24 10:23:42 +08:00

27 lines
536 B
Python

import requests
conn = requests.Session()
url = "http://127.0.0.1"
r = conn.get(url)
# print(r.json())
print(r.headers)
# url = "http://127.0.0.1/login"
# data = {
# "username": "admin",
# "password": "admin123"
# }
# r = requests.post(url, json=data)
# print(r.json())
# token = r.headers.get("set-cookie")
# headers = {
# "Cookie": token
# }
# print(token)
url = "http://127.0.0.1/users/me"
token = r.headers.get('set-cookie')
headers = {
"Cookie": f"token={token}"
}
r = conn.get(url, headers=headers)
print(r.text)