refactor: add douban httpclient
This commit is contained in:
parent
ed1a72dad6
commit
7e4246003d
|
@ -6,7 +6,6 @@ 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;
|
||||
|
||||
|
@ -45,12 +44,9 @@ namespace Jellyfin.Plugin.MetaShark.Controllers
|
|||
}
|
||||
|
||||
HttpResponseMessage response;
|
||||
var httpClient = GetHttpClient();
|
||||
var httpClient = this._httpClientFactory.CreateClient("douban");
|
||||
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();
|
||||
|
@ -80,11 +76,5 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
|
||||
namespace Jellyfin.Plugin.MetaShark
|
||||
{
|
||||
|
@ -38,6 +39,22 @@ namespace Jellyfin.Plugin.MetaShark
|
|||
{
|
||||
return new ImdbApi(ctx.GetRequiredService<ILoggerFactory>());
|
||||
});
|
||||
|
||||
// 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;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue