简体   繁体   English

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

[英]Simulate login action to VBulletin using C#

I trying to write a program (C#) that can login and create new thread into VBulletin forums. 我试着编写一个可以登录并在VBulletin论坛中创建新线程的程序(C#)。 I tried 2 way: 我尝试了两种方式:

1) Use HttpWebRequest : Login is done. 1)使用HttpWebRequest :登录完成。 However creating new thread is fail. 但是,创建新线程失败。 This is posting code: 这是发布代码:

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();
    }

When a execute the code above, no any theard has been created ! 执行上面的代码时,没有创建任何理论!

2) Use WebBrowser control: 2)使用WebBrowser控件:

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

But I cant not submit because the has no name/id, and Login button is same ! 但我不能提交,因为没有名称/ ID,并且登录按钮是相同的! Please tell me how to submit a form without form name/id and button name/id ? 请告诉我如何提交没有表格名称/ ID和按钮名称/ ID的表格?

Thanks ! 谢谢 !

Best regard, 最良好的问候,

Try simulating post data instead of filling out the form: 尝试模拟发布数据而不是填写表单:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM