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

标签 c# post vbulletin

我正在尝试编写一个程序 (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();
    }

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

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");

关于c# - 使用 C# 模拟登录到 VBulletin 的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2453844/

相关文章:

c# - SignalR 如何保持从服务器到客户端的消息顺序

c# - 为什么结构中的字段会丢失其值,而同一类中的字段却不会?

c# - 如何在 C# AspNet Core 中模拟 LoggerFactory

c# - 不使用图形对象测量字符串?

post - Flutter - 处理POST请求中的状态码302

php - 如何删除元描述标签中的网址

php - PHP一键提交多个表单

java - 使用Java发送POST数据

php - 分配一个等于 Include 函数内容的变量

Javascript事件处理程序总是被添加到数组中的最后一个对象