public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { var tokenParam = actionExecutedContext.Request.Headers.Authorization.Parameter; if (tokenParam == null) { CustomNLogger.LogException("Token authorization failed"); } }
public string AddNewSavedText(SavedText savedText) { try { _dbContext.SavedTexts.Add(savedText); return("Entry inserted successfully"); } catch (Exception ex) { CustomNLogger.LogException(ex.Message); return(null); } }
public bool ServiceRunning() { using (var client = new HttpClient()) { var response = client.GetAsync($"{ApiUrl}/status/check"); if (!response.Result.IsSuccessStatusCode) { CustomNLogger.LogException($"TextWebApi at {ApiUrl} is down"); } return(response.Result.IsSuccessStatusCode); } }
public async Task <string> GetResponseFromApi(string contentToSend) { CheckAndSetToken(); using (var client = new HttpClient()) { var transferObject = new SimpleDto { Text = contentToSend }; var contentBody = new StringContent(JsonConvert.SerializeObject(transferObject), Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); var response = await client.PostAsync($"{ApiUrl}/text-infos/count-words", contentBody); if (!response.IsSuccessStatusCode) { CustomNLogger.LogException($"error occurred: \n{response.StatusCode} \n{response.RequestMessage.RequestUri}"); return("There is currently error in communication with API"); } return(await response.Content.ReadAsStringAsync()); } }