public async void sendMsgToServer(string msg) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; var local = ApplicationData.Current.LocalFolder; string postUrl = "http://www.tuling123.com/openapi/api"; if (localSettings.Values["stuId"] == null) { await new MessageDialog("由于您没有登陆不能调戏小秘书", "错误提示").ShowAsync(); return; } string id = localSettings.Values["stuId"].ToString(); string key = "4fd6c3d1d91d4463a6e5dc1af430fc62"; await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextBlock tb = new TextBlock { Text = tbMsg.Text, FontSize = 16, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Foreground = new SolidColorBrush(Colors.Black), Width = 280, FlowDirection = FlowDirection.RightToLeft, TextWrapping = TextWrapping.Wrap }; TuringMsgPanel.Children.Add(tb); }); using (HttpClient client = new HttpClient()) { var kvp = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("userid", id), new KeyValuePair <string, string>("info", tbMsg.Text), new KeyValuePair <string, string>("key", key), }; var content = new HttpFormUrlEncodedContent(kvp); HttpResponseMessage response = await client.PostAsync(new Uri(postUrl), content); if (response.EnsureSuccessStatusCode().StatusCode.ToString().ToLower() == "ok") { string responseBody = await response.Content.ReadAsStringAsync(); string[] stringArr = responseBody.Split('"'); await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextBlock tb = new TextBlock { Text = stringArr[5], FontSize = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 100, 180)), Width = 280, TextWrapping = TextWrapping.Wrap }; TuringMsgPanel.Children.Add(tb); }); // Jsonb JSONToObject(responseBody); //var json = JsonSerializer.Create(); //Rootobject thinw = json.Deserialize<Rootobject>(new JsonTextReader(new StringReader(responseBody))); } } TuringScrollView.ChangeView(null, TuringScrollView.ActualHeight + TuringScrollView.ScrollableHeight, null); tbMsg.Text = ""; }
private async void TuringBtn_Click(object sender, RoutedEventArgs e) { TuringMsgPanel.Children.Clear(); await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TextBlock tb = new TextBlock { Text = "我能为你做点什么?", FontSize = 20, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 100, 180)), Width = 280, TextWrapping = TextWrapping.Wrap }; TuringMsgPanel.Children.Add(tb); }); TuringScrollView.ChangeView(null, TuringScrollView.ActualHeight + TuringScrollView.ScrollableHeight, null); }