diff --git a/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs b/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs index ba5e518..c3c9848 100644 --- a/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs +++ b/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using MediaBrowser.Common.Net; using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Model; @@ -44,9 +45,12 @@ namespace Jellyfin.Plugin.MetaShark.Controllers } HttpResponseMessage response; - var httpClient = this._httpClientFactory.CreateClient("douban"); + var httpClient = GetHttpClient(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) { + requestMessage.Headers.Add("User-Agent", DoubanApi.HTTP_USER_AGENT); + requestMessage.Headers.Add("Referer", DoubanApi.HTTP_REFERER); + response = await httpClient.SendAsync(requestMessage); } var stream = await response.Content.ReadAsStreamAsync(); @@ -76,5 +80,11 @@ namespace Jellyfin.Plugin.MetaShark.Controllers var isLogin = await _doubanApi.CheckLoginAsync(CancellationToken.None); return new ApiResult(isLogin ? 1 : 0, isLogin ? "logined" : "not login"); } + + private HttpClient GetHttpClient() + { + var client = _httpClientFactory.CreateClient(NamedClient.Default); + return client; + } } } diff --git a/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs b/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs index 658dcb1..7c0b590 100644 --- a/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs +++ b/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using MediaBrowser.Controller.Persistence; using System.Net.Http; -using System.Net; namespace Jellyfin.Plugin.MetaShark { @@ -39,22 +38,6 @@ namespace Jellyfin.Plugin.MetaShark { return new ImdbApi(ctx.GetRequiredService()); }); - - // douban httpclient 忽略 ssl 证书校验 - serviceCollection.AddHttpClient("douban", client => - { - client.DefaultRequestHeaders.Add("User-Agent", DoubanApi.HTTP_USER_AGENT); - client.DefaultRequestHeaders.Add("Referer", DoubanApi.HTTP_REFERER); - }).ConfigurePrimaryHttpMessageHandler(() => - { - var handler = new HttpClientHandler - { - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, - ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true - }; - return handler; - }); - } } }