如何通过POST请求正确地使用Python请求进行身份验证

2024-03-29 10:15:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为iObeya使用restapi,我希望使用Python请求,但是目前我无法通过服务器进行身份验证。文档声明您可以使用POST请求进行身份验证,并且在返回时,您应该在身份验证正确时获得一个名为“JSESSIONID”的cookie。你知道吗

到目前为止,我有:

url = 'https://link-to.com/iobeya/'
auth_url = 'https://link-to.com/iobeya/j_spring_security_check'
headers = {"content-type": "application/x-www-form-urlencoded; charset=utf-8"}

session = requests.Session()
session.auth = ("username", "password")

auth = session.post(url, verify=False)

r = session.get(url, verify=False, headers=headers)

print(r.status_code)

print(r.headers)

print(r.cookies)

Cookie的返回为空。这是使用POST方法执行身份验证请求的正确方法吗?你知道吗

下面是描述auth API工作原理的页面: enter image description here


Tags: to方法httpscomauth身份验证falseurl
1条回答
网友
1楼 · 发布于 2024-03-29 10:15:11

它只想让你用usernamepassword写一篇普通的文章。你知道吗

auth_url = 'https://link-to.com/iobeya/j_spring_security_check'

session = requests.Session()
auth = session.post(auth_url, data={'username': username, 'password': password})

相关问题 更多 >