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

112
Vistas
Content-length body with mixed latin and chinese characters

I am defining the Content-Length of an HTTP request but because sometimes it might contain chinese characters when it gets to the response side of things, it gets truncated.

I have been trying to get the right way to set the content-length of a mixed Chinese/Latin String but with no luck. it keeps getting truncated.

headers["Content-Length"] = data.length;   //fails
{ \"query\": \"周杰伦\", \"type\": \"artist\"} //gets truncated

{ \"query\": \"gennaro\", \"type\": \"artist\"} //successful request

Can anyone suggest how to calculate the second string length for the content-length header properly?

NOTE: the body is stringified from JSON before it is sent over.

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The fix this issue , I used TextEncoder which allow me to encode it to utf8 and then count it in the correct way.

let bodyLength = (new TextEncoder().encode(dataBody)).length;
about 4 years ago · Juan Pablo Isaza Denunciar
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