Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

964
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda