Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

960
Visualizações
HttpClient Exception 'The response ended prematurely' when actual response length not match Content-Length header

How I can fix HttpClient Exception when the actual response length is smaller than Content-Length header

The response ended prematurely, with at least 4508 additional bytes expected.

The response ended prematurely, with at least 783 additional bytes expected.

I fixed this exception by reading the response content character by character until the exception happens

var response = await client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var stream = await response.Content.ReadAsStreamAsync();

using var streamReader = new StreamReader(stream);
var content = "";
try
{
    do
    {
        content += (char)streamReader.Read();
    }
    while (!streamReader.EndOfStream);
}
catch (Exception ex)
{
}

but I didn't think this is the right or the optimal solution,

can I make HttpClient ignore the Content-Length header?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda