2024-03-12 16:15:15 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CSS_Solution.Request
|
|
|
|
|
{
|
|
|
|
|
public class HttpClientPool
|
|
|
|
|
{
|
|
|
|
|
HttpClient[] httpClients = new HttpClient[5];
|
2024-03-14 00:02:17 +08:00
|
|
|
|
HttpClientHandler[] httpClientHandlers = new HttpClientHandler[5];
|
2024-03-12 16:15:15 +08:00
|
|
|
|
public HttpClientPool()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < httpClients.Length; i++)
|
2024-03-14 00:02:17 +08:00
|
|
|
|
if (i == (int)Request_Type.to_course)
|
|
|
|
|
{
|
|
|
|
|
httpClientHandlers[i] = new HttpClientHandler() { AllowAutoRedirect = false };
|
|
|
|
|
httpClients[i] = new HttpClient(httpClientHandlers[i]);
|
|
|
|
|
}
|
2024-03-12 16:15:15 +08:00
|
|
|
|
else
|
2024-03-14 00:02:17 +08:00
|
|
|
|
{
|
|
|
|
|
httpClientHandlers[i] = new HttpClientHandler();
|
|
|
|
|
httpClients[i] = new HttpClient(httpClientHandlers[i]);
|
|
|
|
|
}
|
2024-03-12 16:15:15 +08:00
|
|
|
|
}
|
2024-03-14 00:02:17 +08:00
|
|
|
|
public HttpClient GetHttpClient(Request_Type request_Type) => httpClients[(int)request_Type];
|
|
|
|
|
public HttpClientHandler GetHttpClientHandler(Request_Type request_Type) => httpClientHandlers[(int)request_Type];
|
2024-03-12 16:15:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|