如何以编程方式登录网站

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

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

接下来=应用程式%2Flinks%2F&为什么= PW和电子邮件= ABC和密码=高清&fw_human =

因此,如果您只是使用该post数据并将其替换为相应的信息,那么这会让我相信,您可以模拟手动登录。

所以从你链接的堆栈溢出,这将采取以下forms:

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