Trying to login to a Xenforo instance using C++

Status
Not open for further replies.

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:

Code:
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();
            http.CookieContainer.Add(httpResponse.Cookies);
            http.AllowAutoRedirect=false;
            HttpWebResponse httpResponse2 = http.GetResponse() as HttpWebResponse;
            // RSS read
            try
            {
                rssReader = new XmlTextReader("http://aerolitegaming.com/forums/in-game-reports.132/");
                rssDoc = new XmlDocument();
                rssDoc.Load(rssReader);
            }
            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)
            {
                Console.WriteLine(e.Message);
            }
            // 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;
            Console.WriteLine(title);
            Console.WriteLine(text);

        }
    }
}

if anyone could help me with this, I would be grateful!
 
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
 
Status
Not open for further replies.
Top Bottom