private void button1_Click(object sender, EventArgs e) { MessageC m = new MessageC() { IdS = u1.Id, IdR = u2.Id, MessageS = textBox1.Text }; sendMessage(m); textBox1.Text = ""; }
private bool sendMessage(MessageC m) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:50086/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("api/sendMessage", m).Result; if (response.IsSuccessStatusCode) { return(true); } return(false); }
private IEnumerable <MessageC> getMessages(MessageC m) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:50086/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("api/getMessages", m).Result; if (response.IsSuccessStatusCode) { var messages = response.Content.ReadAsAsync <IEnumerable <MessageC> >().Result; return(messages); } return(null); }