3
我试图编写一个程序(C#),它可以登录并在VBulletin论坛中创建新线程。我试过2种方式:使用C#模拟登录到VBulletin动作#
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的表单?
谢谢!
最佳方面,
嗨, 感谢您的回复!但是你提供的代码似乎不起作用。它只是重定向到member.php而且状态是un-login。我在VBB 3x和4x上测试过。 请检查它! 最好的方面! – Shinichi 2010-03-16 14:15:57
DId您更改值以符合您的要求?我使用了精确的代码(用户名和密码除外)登录到sweclockers,它的工作就像一个魅力 – 2010-03-16 14:22:34
这是我的代码: string postData =“username = Admin&password = 123456&action = login&url = /”; (“localhost/vbb4x/member.php”,“”,Encoding.UTF8.GetBytes(postData),“Content-Type:application/x-www-form-urlencoded \ r \ n”); 如果你看到错误,告诉我!谢谢 ! – Shinichi 2010-03-16 15:36:07