public HttpResponseMessage SendGetRequestAuth(List <KeyValuePair <string, string> > parameters, string controller, string action, int?id, string token, CusHttpMethod method) { string url; if (controller.ToLower() == "token" && action.ToLower() == "token") { url = CusUrlHelper.MakeForToken(); } else { url = CusUrlHelper.Make(controller, action, id); } var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); var encodedValues = new FormUrlEncodedContent(parameters); if (method == CusHttpMethod.Put) { return(httpClient.PutAsync(url, encodedValues).Result); } return(httpClient.PostAsync(url, encodedValues).Result); }
public HttpResponseMessage SendGetRequestAuthGetDel(string controller, string action, int?id, string token, CusHttpMethod method) { var url = CusUrlHelper.Make(controller, action, id); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); if (method == CusHttpMethod.Delete) { return(httpClient.DeleteAsync(url).Result); } else if (method == CusHttpMethod.Put) { return(httpClient.PutAsync(url, null).Result); } else if (method == CusHttpMethod.Post) { return(httpClient.PostAsync(url, null).Result); } else if (method == CusHttpMethod.Get) { return(httpClient.GetAsync(url).Result); } return(httpClient.GetAsync(url).Result); }