Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!