1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying to login to a Xenforo instance using C++

Discussion in 'General XenForo Discussion and Feedback' started by tomtiger11, May 26, 2014.

Thread Status:
Not open for further replies.
  1. tomtiger11

    tomtiger11 New Member

    I'm trying to login to a Xenforo forum using C#, to give me a message when a thread has been made in a certain area using RSS.

    Here is the code, with passwords ommited:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Net;
    using System.IO;
    using System.Web;
    using System.Xml;
    namespace ConsoleApplication1
        class Program
            static void Main(string[] args)
                XmlTextReader rssReader;
                XmlDocument rssDoc = null;
                XmlNode nodeRss = null;
                XmlNode nodeChannel = null;
                String title;
                String text;
                HttpWebRequest http = WebRequest.Create("http://www.aerolitegaming.com/login/login/") as HttpWebRequest;
                http.KeepAlive = true;
                http.Method = "POST";
                http.AllowAutoRedirect = true;
                http.ContentType = "application/x-www-form-urlencoded";
                string postData = "login=SNIP&register=0&password=SNIP&remember=1&cookie_check=0&_xfToken=";
                byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
                http.ContentLength = dataBytes.Length;
                using (Stream postStream = http.GetRequestStream())
                    postStream.Write(dataBytes, 0, dataBytes.Length);
                HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;
                int y = (int)httpResponse.StatusCode;
                Console.WriteLine(Convert.ToString(y), "Response Code Debug");
                foreach (Cookie c in httpResponse.Cookies)
                    Console.WriteLine(c.Name + " = " + c.Value, "Cookie Debug");
                http = WebRequest.Create("http://www.aerolitegaming.com/") as HttpWebRequest;
                http.CookieContainer = new CookieContainer();
                HttpWebResponse httpResponse2 = http.GetResponse() as HttpWebResponse;
                // RSS read
                    rssReader = new XmlTextReader("http://aerolitegaming.com/forums/in-game-reports.132/");
                    rssDoc = new XmlDocument();
                catch (WebException e)
                    Console.WriteLine("This program is expected to throw WebException on successful run." +
                                        "\n\nException Message :" + e.Message);
                    if (e.Status == WebExceptionStatus.ProtocolError)
                        Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
                        Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
                catch (Exception e)
                // Loop for the <rss> tag
                for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
                    // If it is the rss tag
                    if (rssDoc.ChildNodes[i].Name == "rss")
                        // <rss> tag found
                        nodeRss = rssDoc.ChildNodes[i];
                // Loop for the <channel> tag
                for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
                    // If it is the channel tag
                    if (nodeRss.ChildNodes[i].Name == "channel")
                        // <channel> tag found
                        nodeChannel = nodeRss.ChildNodes[i];
                // Set the labels with information from inside the nodes
                title = "Title: " + nodeChannel["title"].InnerText;
                text = "Description: " + nodeChannel["description"].InnerText;
    if anyone could help me with this, I would be grateful!
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Support is only available to licensed customers or associated accounts.

    If you own a license, ensure you associate your forum user name with it here: Customer Area
    Liam W likes this.
Thread Status:
Not open for further replies.

Share This Page