1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-24 22:36:19 -04:00

Use modern HttpClient

Co-Authored-By: ta264 <ta264@users.noreply.github.com>
This commit is contained in:
Qstick
2021-11-13 15:10:42 -06:00
committed by Mark McDowall
parent bff1fe7890
commit 4c0fe62dda
69 changed files with 1271 additions and 1060 deletions
@@ -1,3 +1,5 @@
using System;
using System.Net.Http;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
@@ -26,13 +28,19 @@ namespace NzbDrone.Core.Notifications.Webhook
.Accept(HttpAccept.Json)
.Build();
request.Method = (HttpMethod)settings.Method;
request.Method = settings.Method switch
{
(int)WebhookMethod.POST => HttpMethod.Post,
(int)WebhookMethod.PUT => HttpMethod.Put,
_ => throw new ArgumentOutOfRangeException($"Invalid Webhook method {settings.Method}")
};
request.Headers.ContentType = "application/json";
request.SetContent(body.ToJson());
if (settings.Username.IsNotNullOrWhiteSpace() || settings.Password.IsNotNullOrWhiteSpace())
{
request.AddBasicAuthentication(settings.Username, settings.Password);
request.Credentials = new BasicNetworkCredential(settings.Username, settings.Password);
}
_httpClient.Execute(request);