C# 如何以编程方式登录到网站

C# 如何以编程方式登录到网站,c#,post,login,screen-scraping,C#,Post,Login,Screen Scraping,我不知道如何以编程方式登录到这个 我在stackoverflow中搜索并找到了,但我仍然不知道该在URL或URI中输入什么。当我键入用户名“abc”和密码“def”并按下按钮时,我得到了以下帖子数据: 下一步=应用程序%2Flinks%2F&why=pw&email=abc&password=def&fw_= 这让我想到,如果你只是使用post数据并用适当的信息替换它,你就可以模拟手动登录 因此,根据您链接的堆栈溢出,其形式如下: string formUrl = "http://ratings

我不知道如何以编程方式登录到这个
我在stackoverflow中搜索并找到了,但我仍然不知道该在URL或URI中输入什么。

当我键入用户名“abc”和密码“def”并按下按钮时,我得到了以下帖子数据:

下一步=应用程序%2Flinks%2F&why=pw&email=abc&password=def&fw_=

这让我想到,如果你只是使用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值来保持您的身份验证状态。

当我键入用户名“abc”和密码“def”并按下按钮时,我将获得以下post数据:

下一步=应用程序%2Flinks%2F&why=pw&email=abc&password=def&fw_=

这让我想到,如果你只是使用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值来维护您的身份验证状态。

使用源代码并更改URL和表单参数。使用源代码并更改URL和表单参数。我尝试过,但没有帮助。我仍然无法输入:使用我的登录cookie:(我真的帮不上忙了,因为我看不到成功登录的标题或任何内容,要重用的cookie标题可能包含在多个集cookie标题中,如果不看到响应数据,很难说。你以前是否使用过Fiddler或Firebug或Chome dev工具等工具来监视网络流量?这样你就可以查看cookie标题了。)请求和响应标题以及手动登录的数据,并将其与编程登录进行比较,以查看缺少的部分。我尝试了它,但没有帮助。我仍然无法输入:使用我的登录cookie:(我真的帮不上忙了,因为我看不到成功登录的标题或任何内容,要重用的cookie标题可能包含在多个集cookie标题中,如果不看到响应数据,很难说。你以前是否使用过Fiddler或Firebug或Chome dev工具等工具来监视网络流量?这样你就可以查看cookie标题了。)请求和响应头以及手动登录的数据,并将其与编程登录进行比较,以查看缺少的部分。