I have an authorization method:

public static int Auth(string username, string password) { var pairs = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("grant_type", "password"), new KeyValuePair<string, string>("username", username), new KeyValuePair<string, string>("password", password), }; var content = new FormUrlEncodedContent(pairs); ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; using (var client = new HttpClient()) { var response = client.PostAsync(baseAdress + "Token", content).Result; access_token = response.Content.ReadAsStringAsync().Result; return Convert.ToInt32(response.StatusCode); } } 

When calling, I have to enter arguments, they are taken from my texbox `s:

 if (Command.Auth(Username.Text, Password.Text) == 200) { MessageBox.Show("Авторизация выполнена!"); } else { MessageBox.Show(Command.access_token); } 

The problem is that the authorization fails, but the fact is that the wpf elements somehow convey the values ​​incorrectly, because the same method works in Windows Forms. Yes, and in WPF, it also partially works, but if only I enter the values ​​manually, like this:

 if (Command.Auth("test123@mail.ru", "1234567890qwertY-") == 200) { MessageBox.Show("Авторизация выполнена!"); } else { MessageBox.Show(Command.access_token); } 

Help solve the problem

  • Magic, not otherwise. Take Fiddler and see what really goes away - Andrew NOP
  • Show your UI, give a reproducible example. Without it, this is some kind of underground knock for the time being. - VladD
  • And how is your password in the textbox? Maybe he just does not transmit - Anton Shakalo

0