Classasync.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Newtonsoft.Json;
  2. using System.Net;
  3. namespace BlazorApp
  4. {
  5. public class Classasync
  6. {
  7. static string? responseBody = null;
  8. public static List<BlazorApp.region> regions = new List<BlazorApp.region>();
  9. static string? responseBody1 = null;
  10. public static List<BlazorApp.ReciplentMessage> message = new List<BlazorApp.ReciplentMessage>();
  11. public static string passwordtrue;
  12. async public static Task valera()
  13. {
  14. using (var client = new HttpClient())
  15. {
  16. client.BaseAddress = new Uri("https://localhost:7152/");
  17. HttpResponseMessage response = await client.GetAsync("WeatherForecast");
  18. if (response.IsSuccessStatusCode)
  19. {
  20. responseBody = await response.Content.ReadAsStringAsync();
  21. regions = JsonConvert.DeserializeObject<List<BlazorApp.region>>(responseBody);
  22. }
  23. }
  24. }
  25. async public static Task valera1()
  26. {
  27. using (var client = new HttpClient())
  28. {
  29. client.BaseAddress = new Uri("https://localhost:7152/");
  30. HttpResponseMessage response = await client.GetAsync("WeatherForecast/GetReciplentMessage");
  31. if (response.IsSuccessStatusCode)
  32. {
  33. responseBody1 = await response.Content.ReadAsStringAsync();
  34. message = JsonConvert.DeserializeObject<List<BlazorApp.ReciplentMessage>>(responseBody1);
  35. }
  36. }
  37. }
  38. async public static Task checkLoginAndPassword(string login, string password)
  39. {
  40. using (var client = new HttpClient())
  41. {
  42. var requestParams = new Dictionary<string, string>
  43. {
  44. {"login",login},
  45. {"password",password}
  46. };
  47. var requestUri = new Uri("https://localhost:7152/WeatherForecast/GetUserRole");
  48. var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}"));
  49. var fullUri = $"{requestUri}?{queryString}";
  50. HttpResponseMessage response = await client.GetAsync(fullUri);
  51. if (response.IsSuccessStatusCode)
  52. {
  53. }
  54. else
  55. {
  56. passwordtrue = "Вы ввели неверные данные для входа";
  57. }
  58. }
  59. }
  60. }
  61. }