I dont know how to programmatically login to this site I've searched through stackoverflow and found this, but I still don't know what to put into URL or URI.
Asked
Active
Viewed 2,968 times
0
-
1Use the code from [this answer](http://stackoverflow.com/questions/930807/c-sharp-login-to-website-via-program/931030#931030) and change the URL and form parameters. – Shadow The GPT Wizard Nov 09 '11 at 13:43
1 Answers
4
When I just type in username 'abc' and password 'def' and hit the button I get the following post data:
next=apps%2Flinks%2F&why=pw&email=abc&password=def&fw_human=
So that leads me to beleive if you just use that post data and replace it with the appropriate information, you can simulate a manual login.
So from the stack overflow you linked, this would take the form:
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"];
Note that in future requests you will need to then use whatever the cookie value that is returned to maintain your authenticated status.

Paul Tyng
- 7,924
- 1
- 33
- 57
-
I tried it but it did not helped. I still cannot enter: http://ratings-plus.webs.com/apps/links/ using my login cookie :( – Qbunia Nov 09 '11 at 21:11
-
I can't really help anymore since I can't see the headers or anything of a successful login, the cookie header to reuse may be contained in multiple set-cookie headers, its hard to say without seeing the response data. Have you used a tool like Fiddler or Firebug or the Chome dev tools to watch network traffic before? That way you can view the request and response headers and data of a manual login and compare that to your programmatic login to see the missing pieces. – Paul Tyng Nov 09 '11 at 21:14