// End point of the PUT Call to the API server public async Task RunAsyncPut(HttpClient client, string putUrlSuffix, string hostName, string requestJsonData) { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (client) { var request = requestJsonData; _logger.Trace("{0} {1}", "REQUEST BODY ->", _masking.MaskMessage(request)); var content = new StringContent(request); content.Headers.ContentType = new MediaTypeHeaderValue(Constants.MediaTypeJson); var uriString = Constants.HttpsUriPrefix + hostName + putUrlSuffix; _logger.Trace("{0} {1}", "URL ->", uriString); try { using (var response = await client.PutAsync(uriString, content)) { _statusCode = (int)(TaskStatus)response.StatusCode; var data = await response.Content.ReadAsStringAsync(); var dataMasked = _masking.MaskMessage(data); var headers = response.Headers.ToString(); _response = new Response(_statusCode, headers, dataMasked); } } catch (TaskCanceledException e) { ExceptionUtil.Exception( $"{Constants.ErrorPrefix} Network Error: Connection could not be established.", e.StackTrace); } catch (Exception e) { ExceptionUtil.Exception(e.Message, e.StackTrace); } } }
// End point of the GET Call to the API server public async Task RunAsyncGet(HttpClient client, string getUrlSuffix, string hostName) { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (client) { var uriString = Constants.HttpsUriPrefix + hostName + getUrlSuffix; _logger.Trace("{0} {1}", "URL ->", uriString); try { using (var response = await client.GetAsync(new Uri(uriString))) { _statusCode = (int)(TaskStatus)response.StatusCode; var data = await response.Content.ReadAsStringAsync(); var dataMasked = _masking.MaskMessage(data); var headers = response.Headers.ToString(); _response = new Response(_statusCode, headers, dataMasked); } } catch (TaskCanceledException e) { ExceptionUtil.Exception( $"{Constants.ErrorPrefix} Network Error: Connection could not be established.", e.StackTrace); } catch (Exception e) { ExceptionUtil.Exception(e.Message, e.StackTrace); } } }