public static string Delete(this RestApiClient networkClient, string url, string content) { var httpRequest = networkClient.CreateDeleteRequest(url, content); var httpClient = networkClient.HttpClient; var response = httpClient.SendAsync(httpRequest).Result; var responseContent = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { return(responseContent); } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { if (networkClient.ShallRefreshToken()) { if (networkClient.InitiateTokenRefresh()) { return(Delete(networkClient, url, content)); } } } throw new Exception(extractMessageFromErrorResponse(responseContent)); }
public static string Post(this RestApiClient networkClient, string url, string content) { if (content == null) { content = string.Empty; } var httpRequest = networkClient.CreatePostRequest(url, content); var httpClient = networkClient.HttpClient; var response = httpClient.SendAsync(httpRequest).Result; var responseContent = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { CohesityLog.Instance.WriteCohesityLog(responseContent); return(responseContent); } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { if (networkClient.ShallRefreshToken()) { if (networkClient.InitiateTokenRefresh()) { return(Post(networkClient, url, content)); } } } CohesityLog.Instance.WriteCohesityLog(extractMessageFromErrorResponse(responseContent)); throw new Exception(extractMessageFromErrorResponse(responseContent)); }