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

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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