//Method post send login resquest and receive response contain access token public static async Task <LoginResponse> PostLogin(LoginRequest request) { var login_response = new LoginResponse(); try { HttpClient client = new HttpClient(); client = RestAPI.Get_HttpClient(); var response = new HttpResponseMessage(); response = await client.PostAsJsonAsync("/api/auth/login/manually", request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { string result = response.Content.ReadAsStringAsync().Result; login_response = JsonConvert.DeserializeObject <LoginResponse>(result); } } catch (Exception e) { Console.WriteLine(e); } return(login_response); }
//Get HttpClient was added token in header private static HttpClient Get_HttpClient_Token() { HttpClient client = new HttpClient(); client = RestAPI.Get_HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LoginResponse.access_token); return(client); }