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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user