使用Python请求ASP.NET身份验证

2024-03-27 14:42:55 发布

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

我想我在正确的轨道上ASP.NET身份验证。我正在尝试使用请求将凭据传递到网站。以下是我从chrome上获取的标题和网络信息:

 Remote Address: REMOVED
Request URL: https://REMOVED/default.aspx

Request Method: POST
Status Code: 302 Found

Request Headers:

POST /default.aspx HTTP/1.1 
Host: REMOVED 
Connection: keep-alive 
Content-Length: 928 
Cache-Control: max-age=0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
Origin: https://REMOVED 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 
Content-Type: application/x-www-form-urlencoded 
Referer: https://REMOVED/default.aspx 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Cookie: ASP.NET_SessionId=REMOVED; BIGipServerpool_REMOVED_dmz_80=REMOVED.REMOVED.0000; AUTHCDB=**REMOVED**

Form Data:
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE: /wEP**REMAINDER REMOVED**
__EVENTVALIDATION: /wEd**REMAINDER REMOVED**
jsCheck:
ddlEngine:REMOVED:13008
Username:
Password:
btnLogin.x: 42
btnLogin.y: 9
btnLogin: Login

Response Headers:

Cache-Control: private
Content-Length: 132
Content-Type: text/html; charset=utf-8
Date: Fri, 13 Jun 2014 00:59:13 GMT
Location: /Dashboard.aspx
Server: Microsoft-IIS/7.5
Set-Cookie: AUTHCDB=**REMOVED**; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

这是我写的剧本:

^{pr2}$

我能使用Python请求登录到使用ASP.NET?如果是这样的话,这是将凭证传递到网站的正确方法吗?作为参考,我试图登录的网站是一个公司服务器监视器。在


Tags: httpsdefaultnetapplication网站requestcontentpost
2条回答

我也在和一些人合作ASP.net现在,由于对“请求”模块比较熟悉,我想我应该试着帮上忙。在

据我所知,请求以这种方式支持基本身份验证:

from requests.auth import HTTPBasicAuth
requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))

在这种情况下,您可能需要导入一个与ASP.net并将其直接插入请求的auth函数中。在

希望这有帮助!在

看起来类似的问题是发布了here和{a2}。我一直在使用RoboBrowser,这让搞乱ASPX变得简单多了。在

from robobrowser import RoboBrowser

login_url = 'http://example.com/Login.aspx'
username = 'JohnDoe'
password = 'passwd'

browser = RoboBrowser(history=True)
# This gets all the ASPX stuff, __VIEWSTATE and friends
browser.open(login_url)
signin = brower.get_form(id='aspnetForm')
signin["jsCheck"].value = ''
signin["ddlEngine"].value = "REMOVED:13008"
signin["Username"].value = username
signin["Password"].value = password
signin["btnLogin.x"].value = "42"
signin["btnLogin.y"].value = "9"
signin["btnLogin"].value = "Login"
browser.submit_form(signin)

相关问题 更多 >