我正在尝试使用 Windows 8 应用商店应用程序中的 HttpWebRequest 登录网站。登录表单如下所示:
<form method="post" action="" onsubmit="javascript:return FormSubmit();">
<div>
<div>
<span>gebruikersnaam</span>
<input size="17" type="text" id="username" name="username" tabindex="1" accesskey="g" />
</div>
<div>
<span>wachtwoord</span>
<input size="17" type="password" id="password" name="password" maxlength="48" tabindex="2" accesskey="w" autocomplete="off" />
</div>
<div class="controls">
<input type="submit" id="submit" accesskey="l" value="inloggen" tabindex="4" class="button"/>
</div>
<!-- The following hidden field must be part of the submitted Form -->
<input type="hidden" name="lt" value="_s3E91853A-222D-76B6-16F9-DB4D1FD397B7_c8424159E-BFAB-EA2A-0576-CD5058A579B4" />
<input type="hidden" name="_eventId" value="submit" />
<input type="hidden" name="credentialsType" value="ldap" />
</div>
</form>
除了名为“lt”的隐藏输入之外,我能够发送大部分必需的输入。这是出于安全目的随机生成的代码,因此我无法在脚本中对其进行硬编码。我当前的脚本是这样的:
HttpWebRequest loginRequest2 = (HttpWebRequest)WebRequest.Create(LOGIN_URL_REDIRECT);
loginRequest2.CookieContainer = CC;
loginRequest2.Method = "POST";
loginRequest2.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
loginRequest2.ContentType = "application/x-www-form-urlencoded";
loginRequest2.Headers["Accept-Encoding"] = "gzip,deflate";
loginRequest2.Headers["Accept-Language"] = "en-us";
StreamWriter sw = new StreamWriter(await loginRequest2.GetRequestStreamAsync());
sw.Write("username=" + userName + "&password=" + passWord + "&_eventId=submit&credentialsType=ldap");
await sw.FlushAsync();
HttpWebResponse response2 = (HttpWebResponse)await loginRequest2.GetResponseAsync();
在执行请求之前,如何获取隐藏输入“lt”的内容?