コード例 #1
0
        private static async Task ParseUserInfoFromHtml()
        {
            HttpResponseMessage message = await App.HttpClient.GetAsync(new Uri("http://neihanshe.cn/set", UriKind.Absolute));

            var contentType = message.Content.Headers.ContentType;

            if (contentType != null && string.IsNullOrEmpty(contentType.CharSet))
            {
                contentType.CharSet = "utf-8";
            }
            string returnHtml = await message.Content.ReadAsStringAsync();

            using (StringReader sr = new StringReader(returnHtml))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Contains("账号名称:")) // 用户名
                    {
                        string str      = line.Substring(line.LastIndexOf("value=", StringComparison.Ordinal));
                        string username = str.Split('\"')[1];
                        SettingUtils.Save("username", username);
                    }
                    if (line.Contains("<div class=\"avatar\">"))    //用户头像
                    {
                        string avatar = line.Split('\"')[3];
                        SettingUtils.Save("avatar", avatar);
                    }
                }
            }
        }
コード例 #2
0
        public async static Task <bool> UserLogin(string username, string password)
        {
            bool status = await Login(username, password);

            if (status)
            {
                SettingUtils.Save("loginname", username);
                SettingUtils.Save("password", password);
                // 获取登录用户信息
                await ParseUserInfoFromHtml();
            }
            return(status);
        }