如何以编程方式登录网站

本文关键字:登录 网站 方式 编程 | 更新日期: 2023-09-27 18:13:52

我不知道如何以编程方式登录到这个网站我已经通过stackoverflow搜索并发现了这个,但我仍然不知道该在URL或URI中放入什么

如何以编程方式登录网站

当我输入用户名'abc'和密码'def'并点击按钮时,我得到以下帖子数据:

下=

应用% 2 flink % 2的原因= pw&电子邮件= abc&密码= def& fw_human =

所以这让我相信,如果你只是使用post数据并用适当的信息替换它,你可以模拟手动登录。

那么从你链接的堆栈溢出中,它的形式是:

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值来维护您的身份验证状态。