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

2023-11-29

我试图编写一个程序(C#),可以登录 VBulletin 论坛并创建新线程。我尝试了2种方式:

1) Use HttpWeb请求: 登录完成。但是创建新线程失败。这是发布代码:

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

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

2)使用Web浏览器控件:

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

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

Thanks !

最良好的问候,


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

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");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 C# 模拟 VBulletin 的登录操作 的相关文章

随机推荐