我想为asp密码保护的网页开发自动报废。我有这个页面的登录名/密码。报废密码保护asp页面
首先,通过firefox在授权期间查看Firebug日志。我发现的:
- 当我打开登录页面时,我用“__RequestVerificationToken”得到cookie。即
http://mysite
- 当我按下登陆按钮FF使POST查询
http://mysite/Account/Login
带参数的用户名,密码和__RequestVerificationToken,也它使用的cookie保存在步骤1中 - 在成功授权的情况下,我得到另一个饼干.ASPXAUTH并进入
http://mysite/Account/Index
(页,我想放弃)
我的代码
//1. Get __RequestVerificationToken cookie
$urlLogin = "http://mysite";
$cookieFile = "cookie.txt";
$regs=array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlLogin);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_STDERR,$f = fopen("answer.txt", "w+"));
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
$data=curl_exec($ch);
//2. Parse token value for the post request
$hash=file_get_contents("answer.txt");
preg_match_all('/=(.*); p/i',$hash, $regs);
//3. Make a post request
$postData = '__RequestVerificationToken='.$regs[1][0].'&UserName=someLogin'.'&Password=somePassword';
$urlSecuredPage = "http://mysite/Account/Login";
curl_setopt($ch, CURLOPT_URL, $urlSecuredPage);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
$data = curl_exec($ch);
curl_close($ch);
在步骤3我的cookie保存在步骤1中与__Requ的新值改写estVerificationToken。我不明白为什么会发生。因此,我无法授权由于__RequestVerificationToken错误而导致HTTP 500错误。
我在哪里错了?
你'__RequestVerificationToken'是会话相关的,据我得到,只要用户得到验证,'的价值__RequestVerificationToken'正确的代码被修改,只对该用户保持有效,一旦用户注销,值将再次改变。所以基于此来转变你的逻辑。我认为。 – saveATcode
saveATcode - 对 - __RequestVerificationToken是会话依赖的,但它在步骤1到步骤3的FF中仍然相同。只有关闭浏览器并再次访问站点时,它才会更改。 –
在步骤3中,我的cookie在步骤1中保存,并以__RequestVerificationToken的新值重写。你在你的问题中写了这个,这意味着错误在其他地方.. – saveATcode