这是cURL,直接从开发工具复制过来的:
curl "https://*.php" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Content-Type: application/x-www-form-urlencoded" -H "Origin: https://moodle.upm.es" -H "DNT: 1" -H "Connection: keep-alive" -H "Referer: https://moodle.upm.es/titulaciones/oficiales/login/auth_index.php" -H "Cookie: **********" -H "Upgrade-Insecure-Requests: 1" --data-raw "password=***********"%"3D"%"3D&username=**********&logintoken=***********"
The reponse is a 303 code
当我尝试在Python中做同样的事情时:
mainsession = requests.post('https://*.php', headers=header, cookies=cookies, data=data)
返回一个200码,响应是一个错误页面。
我已经正确复制了所有的头和我的代码的其他Post请求工作得很好,所以我不知道我做错了什么。
您应该在curl命令中添加-L——location标志,以跟随重定向:
curl -L "https://moodle.upm.es/titulaciones/oficiales/login/index.php"