使用C#模拟登陆行动vBulletin

使用C#模拟登陆行动vBulletin

本文介绍了使用C#模拟登陆行动vBulletin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个程序(C#),可以登录并创建新的线程进入vBulletin论坛。我试过2路:

I trying to write a program (C#) that can login and create new thread into VBulletin forums. I tried 2 way:

1)使用的HttpWebRequest :登录完成。但是创造新的线程失败。这是张贴代码:

1) Use HttpWebRequest : Login is done. 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();
    }

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

When a execute the code above, no any theard has been created !

2)使用WebBrowser控件:

2) Use WebBrowser control:

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



但我不能没有提交,因为没有名称/ ID和登录按钮是一样的!请告诉我如何提交表单没有形式的名称/ ID和按钮的名称/ ID?

But I cant not submit because the has no name/id, and Login button is same ! Please tell me how to submit a form without form name/id and button name/id ?

谢谢!

最佳方面,

推荐答案

尝试模拟后的数据,而不是填写表单:

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

这篇关于使用C#模拟登陆行动vBulletin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:43