我如何登录到一个VBulletin PHP网站与c#

本文关键字:VBulletin 一个 PHP 网站 何登录 登录 | 更新日期: 2023-09-27 18:19:14

如何使用c#登录VBulletin PHP网站?

我有一个基于php的VBulletin社区代码板。

我想通过我将构建的c#程序登录到董事会。

我的问题是,即使我已经证明了数据查询中所有必要的变量,如vb_login_username="USERNAME"&vb_login_md5password="MD5 # OF PASSWORD",当我尝试登录时,网站只是响应主页的HTML,好像我根本没有尝试登录。

我必须为网站设置哪些其他数据才能将我的程序识别为浏览器,我如何才能正确地向VBulletin board进行查询以登录?

我如何登录到一个VBulletin PHP网站与c#

这是另一个网站上的人做的事情,似乎可以解决你的问题。

嗯,在我的一个程序中,必须登录vBulletin(并保持登录)所以我写了一个函数来做这个。

要求:System.Net;,先,

    static string login(string url, string username, string password)
    {
        HttpWebRequest req  = (HttpWebRequest)WebRequest.Create(url);
        string cookie       = "";
        string values       = "vb_login_username="+username+"&vb_login_password="+password
                            + "securitytoken=guest&"
                            + "cookieuser=checked&"
                            + "do=login";
        req.Method          = "POST";
        req.ContentType     = "application/x-www-form-urlencoded";
        req.ContentLength   = values.Length;
        CookieContainer a   = new CookieContainer();
        req.CookieContainer = a;
        System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error
        using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) 
      {
          writer.Write(values);           }
        HttpWebResponse c = (HttpWebResponse)req.GetResponse();
        foreach (Cookie cook in c.Cookies)            {
          cookie = cookie + cook.ToString() + ";";            }
        return cookie;
    }

它返回cookie数据,以便在加载站点的其他页面时,你可以发送cookies并保持登录状态头。添加("cookie", cookie)方法。还有一个例子;

string cookie = login("forum.codecall.net/login.php?do=login", "username", "password"); // include http and www (I don't have 10

论坛帖子)Console.Write(饼干);

Console.Read ();

这只在vBulletin 3上测试过。x版本。

我认为您的问题可能是您没有编码您的字符串以匹配vbullet使用的编码和/或您可能没有正确发送请求。

Function login(ByVal url As String, ByVal username As String, ByVal password As String) As String
        Dim req As Net.HttpWebRequest = Net.WebRequest.Create(url)
        Dim cookie As String = String.Empty
        Dim values As String = "vb_login_username=" + username + "&vb_login_password=" + password _
                            + "securitytoken=guest&" _
                            + "cookieuser=checked&" _
                            + "do=login"
        req.Method = "POST"
        req.ContentType = "application/x-www-form-urlencoded"
        req.ContentLength = values.Length
        Dim a As Net.CookieContainer = New Net.CookieContainer()
        req.CookieContainer = a
        System.Net.ServicePointManager.Expect100Continue = False ' prevents 417 error
        Using writer As IO.StreamWriter = New IO.StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)
            writer.Write(values)
        End Using
        Dim c As Net.HttpWebResponse = req.GetResponse()
        For Each cook In c.Cookies
            cookie = cookie + cook.ToString() + ";"
        Next
        Return cookie
    End Function