private async void loginButton_ClickAsync(object sender, RoutedEventArgs e) { if (usernameBox.Text == String.Empty) { MessageBox.Show("Please enter a username!", "Error"); return; } if (passwordBox.Password == String.Empty) { MessageBox.Show("Please enter a password!", "Error"); return; } client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); JObject loginData = new JObject(new JProperty("username", usernameBox.Text), new JProperty("password", passwordBox.Password)); var response = await client.PostAsync("authenticate", new StringContent(loginData.ToString(), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { HttpHeaders headers = response.Headers; IEnumerable <string> values; string token = String.Empty; if (headers.TryGetValues("token", out values)) { token = values.First(); } this.Hide(); Checkout checkout = new Checkout(token); checkout.Owner = Application.Current.MainWindow; checkout.Show(); } else { MessageBox.Show("Invalid Credentials", "Error"); } }