tags:

views:

361

answers:

2

Hi,

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

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

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

2) Use WebBrowser control:

 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 ! Please tell me how to submit a form without form name/id and button name/id ?

Thanks !

Best regard,

A: 

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");
Oskar Kjellin
Hi,Thanks for you reply ! However the code you provide seem not work. It just redirect to member.php only and status is un-login. I tested on VBB 3x and 4x.Please review it !Best regard !
Shinichi
DId you change the values to match yours? I used that exact code (Except username and password) to sign into sweclockers and it worked like a charm
Oskar Kjellin
This is my code:string postData = "username=AdminwebBrowser1.Navigate("localhost/vbb4x/member.php","", Encoding.UTF8.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");Tell me if you see mistakes ! Thanks !
Shinichi
Oskar Kjellin
Thanks for your support, auto login feature is done ! However, I can not create new thread via post method. Can you help me again ?
Shinichi
Your should be able to do it the same way. Just check the form that is on the createthread page and take all the values from there. Make sure that you navigate to the action of the form
Oskar Kjellin
I tried it the same way but it failed. Cause the posting coding can not get SecurityToken of the loggin action before. That 's a great anti-spamming featue :)
Shinichi
+1  A: 

vBulletin does not accept data posted from any domain not in the white list, it's a setting in the admin panel, I think "General Settings". Try putting the IP or the machine the program is running on in there and see if it works.

Sly_Ripper