答案 0 :(得分:4)
当我输入用户名'abc'和密码'def'并按下按钮时,我会收到以下帖子数据:
下一个应用程式=%2Flinks%2F&安培;为什么= PW&安培;电子邮件= ABC&安培;密码= DEF&安培; fw_human =
因此,如果您只使用该帖子数据并将其替换为相应的信息,那么我就会感到相信,您可以模拟手动登录。
因此,从您链接的堆栈溢出开始,这将采用以下形式:
string formUrl = "http://ratings-plus.webs.com/apps/auth/doLogin"; // NOTE: This is the URL the form POSTs to, not the URL of the form (you can find this in the "action" attribute of the HTML's form tag
string formParams = string.Format("next=apps%2Flinks%2F&why=pw&email={0}&password={1}&fw_human=", "your email", "your password");
string cookieHeader;
WebRequest req = WebRequest.Create(formUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(formParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
WebResponse resp = req.GetResponse();
cookieHeader = resp.Headers["Set-cookie"];
请注意,在将来的请求中,您需要使用返回的cookie值来维护您的身份验证状态。