MyBB Community Forums

Full Version: Post data to Login Form C#
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

Why I need this is not really intresting but I do need it and I tried various methods but couldn't figure it out after my best but at the same time worst attempt since it uses WebClient. But I was really confident it should have work. But it didnt. How can I do this?


Current Code:

static void Main(string[] args)
        {
            var client = new CookieWebClient();
            client.BaseAddress = @"{FORUMURL}";
            var loginData = new NameValueCollection();
            loginData.Add("username", "Coddr");
            loginData.Add("password", "RIGHTPASSWORD");
            client.UploadValues("member.php?action=login", "POST", loginData);
            string htmlSource = client.DownloadString("index.php");
            if (htmlSource.Contains("?action=logout"))
            {
                Console.WriteLine("You are logged in");
            }
            else
            {
                Console.WriteLine("You are logged out");
            }
            Console.ReadKey();
        }
    }
    public class CookieWebClient : WebClient
    {
        private CookieContainer cookie = new CookieContainer();

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                (request as HttpWebRequest).CookieContainer = cookie;
            }
            return request;
        }
    }
You're missing a field:
loginData.Add("action", "do_login");
(2016-08-05, 03:19 PM)Devilshakerz Wrote: [ -> ]You're missing a field:
loginData.Add("action", "do_login");

Thanks! I will directly put this to test and see if I now can also do it via other ways. Ill let you know!

EDIT: Worked