示例#1
0
        private static async Task <HttpResponseMessage> SendRequest(
            HttpClient client,
            WebHookReporterOptions options,
            MemoryStream jsonStream,
            ILogger logger,
            CancellationToken cancellation)
        {
            var request = CreatePostMessage(new Uri(client.BaseAddress + options.Url), jsonStream);

            if (options.Authorization != null)
            {
                request.Headers.Authorization = BuildAuthHeader(options.Authorization);
            }

            options.Headers.ToList().ForEach(header => request.Headers.Add(header.Name, header.Value));

            var response = await client.SendAsync(request, cancellation);

            logger.LogDebug(ReportSentToUrlLog, request.RequestUri.ToString(), response.StatusCode);

            if (!response.IsSuccessStatusCode)
            {
                ThrowHttpRequestException(response);
            }

            return(response);
        }
示例#2
0
 public WebHookReporter(
     IOptionsMonitor <WebHookReporterOptions> options,
     HttpClient client,
     IRetryProvider retryProvider,
     ILogger <WebHookReporter> logger)
 {
     _options       = options.CurrentValue;
     _client        = client;
     _retryProvider = retryProvider;
     _logger        = logger;
 }