Exemplo n.º 1
0
        public static bool Login(LoginData data)
        {
            if (data.Cookies.Count > 0)
            {
                CookieContainer container = new CookieContainer();
                foreach (var cookie in data.Cookies)
                {
                    System.Net.Cookie c = new System.Net.Cookie(cookie.Name, cookie.Value) { Domain = new Uri(data.Address).Host };
                    container.Add(c);
                }

                Client = new CookieWebClient(container);

                return CheckForSuccessfullLogin(data);
            }
            else
            {
                string postData = data.UserNameParameterName + "=" + HttpUtility.UrlEncode(data.UserName)
                    + "&" + data.PasswordParameterName + "=" + data.Password;

                if (!string.IsNullOrEmpty(data.AdditionalParameters))
                {
                    postData += "&" + data.AdditionalParameters;
                }

                Client = new CookieWebClient();

                Client.Login(data.Address, postData);

                return CheckForSuccessfullLogin(data);
            }
        }
Exemplo n.º 2
0
        private static bool CheckForSuccessfullLogin(LoginData data)
        {
            HtmlDocument doc = LoadPage(data.LoginCheckAddress, false);

            if (!string.IsNullOrEmpty(data.ValueToCheckForSuccessfullLogin))
            {
                return doc.DocumentNode.InnerText.Contains(data.ValueToCheckForSuccessfullLogin);
            }

            LogHelper.Error("Kein Feld zum Login-Check gefunden, bitte ValueToCheckForSuccessfullLogin füllen.");
            return false;
        }