Answer the question
In order to leave comments, you need to log in
Authorize request using POST method?
Good afternoon.
I'm trying to get authorization on the WEB resource.
Resource interacts with CSRF Each access requires retrieving CSRF values.
You can use Cookies for this.
How to make a POST request. Putting the necessary HEADERS user_agent data into it and passing the user values, namely user and passwd. Using a page redirect.
There is the following code for python.
import requests
import time
from lxml import html
import re
import json
source = ['https://chatur', 'bate.com/auth/login/']
print(source[0]+source[1])
print(source[0]+"bate.com")
response = requests.get(source[0]+source[1])
#print(response.content)
tree = html.fromstring(response.content)
csrf = tree.xpath('//*[@id="main"]/div/div/form/input/@value')
print(csrf[1])
print(response.headers.get('Set-Cookie'))
jes = response.headers.get('Set-Cookie')
ksrf = response.headers.get('Set-Cookie')
result = re.findall(r'csrftoken=\w+', ksrf)
results = re.findall(r'\w+', str(result))
print(csrf[1], results[1])
print(response.headers.get('Server'))
###############
###############
url = source[0]+source[1]
headers = {
#':authority': 'bate.com',
#':method': 'POST',
#':path': '/auth/login/',
#':scheme': 'https',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'ru,en;q=0.9',
'cache-control': 'max-age=0',
'content-length': '122',
'content-type': 'application/x-www-form-urlencoded',
'cookie': ksrf,
'origin': source[0]+'bate.com',
'referer': source[0]+source[1],
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 YaBrowser/19.12.2.252 Yowser/2.5 Safari/537.36'}
data = 'next=&csrfmiddlewaretoken={csrf[1]}}&username=thorix0&password=Lovacska00&g-recaptcha-response=03AGdBq24NntPLGWn_DrO_3PDWYzO3Ak8bcJnGfj5jj5ThGAQu51lHYDroH11vzDIgVU-8WlbdSqbQMA3n8ERyB3oDq_uY2Kkpgti_rnQeuAC9Q4sBlmYJFtoh7St4um6bjrSADh_TIIlinEj2t8udNAPhxevlowvOvyRmGxM2oIjhJHkPRSQin8Tzsnfu-bOeuISY3_jAI1Q5LR2j_SqhmqhXCLmcG5pGKYgJ2Szyi5AqNhmelhx1dYTvnUdLPHzq-bhSDepzVNBi_rJflsoxnJloP4CdA4j-Vw5gcHz5snLUpSwgt8-uN1Q3k2cUZs_Gx3H57w7EnyscjQIal67vcv1vaW33s5ciS7bgHfrL0EtzW7Cir97I9ZW96drv-pLSTLabzBcOJu5P'
res = requests.post(url, data=data, headers=headers, )
print(res.status_code)
print(res.history)
print(str(res.text))
£
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question