Melhora requisição HTTP no CalendarioService
Utiliza SocketsHttpHandler para descompressão automática (GZip, Deflate, Brotli) e configura HttpRequestMessage com headers detalhados (Host, User-Agent, Accept, Accept-Encoding, Connection) para simular navegador e garantir compatibilidade com o servidor da CCEE. Troca PostAsync por SendAsync. Processamento do JSON permanece inalterado.
This commit is contained in:
parent
864455c8cd
commit
b41d272a7a
@ -1,6 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Application;
|
using Application;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Infrastructure
|
namespace Infrastructure
|
||||||
{
|
{
|
||||||
@ -32,9 +35,31 @@ namespace Infrastructure
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var client = new HttpClient();
|
using var handler = new SocketsHttpHandler
|
||||||
|
{
|
||||||
|
// Adiciona Accept-Encoding automaticamente e faz a descompressão transparente
|
||||||
|
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli
|
||||||
|
};
|
||||||
|
using var client = new HttpClient(handler);
|
||||||
using var content = new FormUrlEncodedContent(values);
|
using var content = new FormUrlEncodedContent(values);
|
||||||
var resp = await client.PostAsync(Url, content, ct);
|
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Post, Url)
|
||||||
|
{
|
||||||
|
Content = content
|
||||||
|
};
|
||||||
|
|
||||||
|
// Headers solicitados
|
||||||
|
request.Headers.Host = "www.ccee.org.br";
|
||||||
|
request.Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||||
|
request.Headers.Accept.Clear();
|
||||||
|
request.Headers.Accept.ParseAdd("*/*");
|
||||||
|
request.Headers.AcceptEncoding.Clear();
|
||||||
|
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
|
||||||
|
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
|
||||||
|
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("br"));
|
||||||
|
request.Headers.Connection.Add("keep-alive");
|
||||||
|
|
||||||
|
var resp = await client.SendAsync(request, ct);
|
||||||
var resposta = await resp.Content.ReadAsStringAsync(ct);
|
var resposta = await resp.Content.ReadAsStringAsync(ct);
|
||||||
|
|
||||||
var alvo = $"Data limite para coleta diária dos dados de medição no SCDE";
|
var alvo = $"Data limite para coleta diária dos dados de medição no SCDE";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user