Beispiel #1
0
        private void LoginXduApp_Click(object sender, RoutedEventArgs e)
        {
            XduApp ixd = new XduApp
                         (
                Username.Text,
                Password.Password
                         );
            HttpClient hc    = ixd.Login();
            JObject    param = new JObject
            {
                { "userId", ixd.UserId }
            };
            string strParam = ixd.BuildQuery(param);

            hc.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
            hc.DefaultRequestHeaders.Add("Accept-Language", "cn");
            if (!hc.DefaultRequestHeaders.Contains("Connection"))
            {
                hc.DefaultRequestHeaders.Connection.Add("keep-alive");
            }
            string  jsonUserInfoReturn = hc.PostAsync("http://202.117.121.7:8080/baseCampus/user/getUserInfo.do", new StringContent(strParam, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
            JObject jsonUserInfo       = (JObject)JsonConvert.DeserializeObject(jsonUserInfoReturn);

            MessageBox.Show($"登录成功。\n\n姓名: {jsonUserInfo["userBaseInfo"]["realName"]}\n\n学院: {jsonUserInfo["userBaseInfo"]["collegeName"]}");
        }
Beispiel #2
0
        private void btnLoginApp_Click(object sender, EventArgs e)
        {
            XduApp ixd = new XduApp
                         (
                txtStuID.Text,
                txtPwd.Text
                         );
            HttpClient hc    = ixd.Login();
            JObject    param = new JObject
            {
                { "userId", ixd.UserId }
            };
            string strParam = ixd.BuildQuery(param);

            hc.DefaultRequestHeaders.TryAddWithoutValidation("token", ixd.Token);
            hc.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
            hc.DefaultRequestHeaders.Add("Accept-Language", "cn");
            hc.DefaultRequestHeaders.Connection.Add("keep-alive");
            string  strRetJson = hc.PostAsync("http://202.117.121.7:8080/baseCampus/user/getUserInfo.do", new StringContent(strParam, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
            JObject jRet       = (JObject)JsonConvert.DeserializeObject(strRetJson);

            MessageBox.Show($"登录成功。\n\n姓名: {jRet["userBaseInfo"]["realName"]}\n\n学院: {jRet["userBaseInfo"]["collegeName"]}");
        }