[英]Simulate login action to VBulletin using C#
我試着編寫一個可以登錄並在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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.