This commit is contained in:
2025-08-16 09:46:25 -03:00
parent 16a6664e7c
commit 4e0566d654

View File

@@ -40,34 +40,41 @@ builder.Services.AddHttpClient("ElectoralApiClient", client =>
client.BaseAddress = new Uri(baseUrl); client.BaseAddress = new Uri(baseUrl);
} }
// Limpiamos headers por defecto y añadimos uno que simula ser un navegador moderno. // Limpiamos los headers por defecto y añadimos uno que simula ser un navegador.
// Esto es crucial para pasar a través de WAFs (Web Application Firewalls). // Esto es crucial para pasar a través de Firewalls de Aplicaciones Web (WAFs)
// que bloquean clientes automatizados no reconocidos.
client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"); client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");
client.DefaultRequestHeaders.Add("Accept", "*/*"); // Opcional, pero ayuda a parecerse más a Postman/navegador
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br"); // Opcional
client.DefaultRequestHeaders.Add("Connection", "keep-alive"); // Opcional
}) })
.ConfigurePrimaryHttpMessageHandler(() => .ConfigurePrimaryHttpMessageHandler(() =>
{ {
return new SocketsHttpHandler var handler = new SocketsHttpHandler
{ {
SslOptions = new SslClientAuthenticationOptions SslOptions = new SslClientAuthenticationOptions
{ {
// Forzamos el protocolo TLS 1.3
EnabledSslProtocols = SslProtocols.Tls13, EnabledSslProtocols = SslProtocols.Tls13,
// --- ¡¡¡LA LÍNEA CLAVE CORREGIDA!!! ---
// Forzamos explícitamente los únicos 3 cipher suites que el servidor acepta.
CipherSuitesPolicy = new CipherSuitesPolicy(new[]
{
TlsCipherSuite.TLS_AES_128_GCM_SHA256,
TlsCipherSuite.TLS_AES_256_GCM_SHA384,
TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256
})
} }
}; };
if (!OperatingSystem.IsWindows())
{
handler.SslOptions.CipherSuitesPolicy = new CipherSuitesPolicy(new[]
{
TlsCipherSuite.TLS_AES_128_GCM_SHA256,
TlsCipherSuite.TLS_AES_256_GCM_SHA384,
TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256
});
}
return handler;
}); });
builder.Services.AddSingleton<IElectoralApiService, ElectoralApiService>(); builder.Services.AddSingleton<IElectoralApiService, ElectoralApiService>();
// --- FIN DE LA SECCIÓN MODIFICADA ---
#endif #endif
builder.Services.AddHostedService<Worker>(); builder.Services.AddHostedService<Worker>();