Exemplo n.º 1
0
        public async Task Login(string userName, string password)
        {
            var loginPostContent = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "0MKKey", "123456" },
                { "DDDDD", userName },
                { "para", "00" },
                { "R1", "0" },
                { "R2", "" },
                { "R6", "0" },
                { "upass", password }
            });

            Uri redirect;

            using (var response = await httpClient.PostAsync(LoginUrl, loginPostContent))
            {
                if (response.StatusCode != HttpStatusCode.Redirect)
                {
                    throw new ApplicationException($"登录请求返回意外的状态代码{response.StatusCode}");
                }

                redirect = response.Headers.Location;
            }
            if (redirect.AbsolutePath == "/3.htm")//登录成功
            {
                Status = ScutStudentClientStatus.LoggedIn;
                return;
            }

            if (redirect.AbsolutePath == "/2.htm")//登录错误
            {
                string http;
                using (var response = await httpClient.GetAsync(errorCodeUrl))
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new ApplicationException($"获取错误信息时返回意外的状态代码{response.StatusCode}");
                    }
                    http = await response.Content.ReadAsStringAsync();
                }
                throw new ScutStudentLoginException(ScutStudentLoginErrorHelper.GetErrorFromHttp(http));
            }
        }
Exemplo n.º 2
0
 public ScutStudentLoginException(ScutStudentLoginError error, Exception inner) : base(ScutStudentLoginErrorHelper.GetErrorHelpText(error), inner) { }