示例#1
0
        public ApiResponse Login(string username, string password)
        {
            if (Ctx.SessionId == null)
            {
                // first, setup a session
                var webServerAPI = new WebServer(Ctx);
                var innerReponse = webServerAPI.SesTokInfo();
                if (Ctx.SessionId == null)
                {
                    throw new System.Exception("Can't get SessionID. Impossible to continue");
                }
            }

            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(password);
            var password4      = getPasswordValue(Ctx.CurrentRequestVerificationToken(), username, password);

            string xml = $@"<?xml version:""1.0"" encoding=""UTF - 8""?>
<request>
<Username>{username}</Username>
<Password>{password4}</Password>
<password_type>4</password_type>
</request>";

            var response = Ctx.Session.HttpPostXML($"{Ctx.Config.BaseURL}/api/user/login", xml);

            if (response.Response.Count == 0)
            {
                Ctx.LoggedIn = true;
            }

            return(response);
        }