使用C#模拟对VBulletin的登录操作

我试着编写一个可以登录并在VBulletin论坛中创建新线程的程序(C#)。 我尝试了两种方式:

1)使用HttpWebRequest :登录完成。 但是,创建新线程失败。 这是发布代码:

public static void CreateNewThread(string url,string fId, string title, string message, string tag) { url += "newthread.php?do=postthread"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); //string result = ""; string values = "subject=" + title + "&message=" + message + "&tag=" + tag + "&do=postthread" + "&f=" + fId + "&s=" + "" ; req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = values.Length; ServicePointManager.Expect100Continue = false; // prevents 417 error using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), Encoding.UTF8)) { writer.Write(values); } HttpWebResponse c = (HttpWebResponse)req.GetResponse(); } 

当执行上面的代码时,没有创建任何理论!

2)使用WebBrowser控件:

  webBrowser1.Document.GetElementById("navbar_username").InnerText = "admin"; webBrowser1.Document.GetElementById("navbar_password").InnerText = "123"; 

但我不能提交,因为没有名称/ ID,并且登录按钮是相同的! 请告诉我如何提交没有表格名称/ ID和按钮名称/ ID的表格?

谢谢 !

最良好的问候,

尝试模拟发布数据而不是填写表单:

 string postData = "username=Kurresmack&password=pw&action=login&url=/"; webBrowser1.Navigate("www.sweclockers.com/forum/member.php", "", System.Text.Encoding.UTF8.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");