How to log in to a vbulletin forum with C#?

Posted by Yustme on Stack Overflow See other posts from Stack Overflow or by Yustme
Published on 2010-03-03T21:56:32Z Indexed on 2010/03/17 13:01 UTC
Read the original article Hit count: 457

Filed under:
|
|

Hi,

I'm trying to log into a vbulletin forum. I got this far:

private string login(string url, string username, string password)
{
string values = "vb_login_username={0}&vb_login_password={1}"
values += "&securitytoken=guest&cookieuser=checked&do=login";

values = string.Format(values, username, password);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
CookieContainer a = new CookieContainer();
req.CookieContainer = a;

System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error

using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
{ writer.Write(values); }

this.response = (HttpWebResponse)req.GetResponse(); 

StringBuilder output = new StringBuilder();

foreach (var cookie in response.Cookies)
{
output.Append(cookie.ToString());
output.Append(";");
}


return output.ToString();
} 

It looks like i am getting logged in, but when i download the page, i can't find my username in it.

Do you guys see anything that i might be doing wrong?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about c#

Related posts about vbulletin