Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending and receiving Arabic over HTTP with indy
#1
Hi, I am sending json data from TIdHTTP to TIdHttpServer that contains arabic letters. But all the letters are received like this ???????????

The json text is in a memo so I convert it to stream using this function "WriteStringToStream" with "IndyTextEncoding_UTF8" encoding and yet the result is always bad. I even tested this using POSTMAN instead of TIdHTTP. What is the correct way to convert text with arabic letters to and from TStream using C++ builder Berlin?

Thanks
Reply
#2
(02-05-2021, 11:36 AM)Ahmed Sayed Wrote: Hi, I am sending json data from TIdHTTP to TIdHttpServer that contains arabic letters. But all the letters are received like this ???????????

That means the characters are going through an ANSI conversion using a charset that doesn't support Arabic. You did not show your code, but I'm guessing you are not telling TIdHTTP and TIdHTTPServer that the JSON is UTF-8 encoded.

(02-05-2021, 11:36 AM)Ahmed Sayed Wrote: The json text is in a memo so I convert it to stream using this function "WriteStringToStream" with "IndyTextEncoding_UTF8" encoding and yet the result is always bad.

It is not enough to just save the JSON to a UTF-8 encoded TStream (and on a side note, you could alternatively use TStringStream with TEncoding.UTF8 instead). Although TIdHTTP will send the TStream bytes as-is, you also have to instruct TIdHTTP to tell the server that the bytes are encoded in UTF-8, so the server can decode them properly.

(02-05-2021, 11:36 AM)Ahmed Sayed Wrote: I even tested this using POSTMAN instead of TIdHTTP.

Same thing. POSTMAN will also have to instruct the server that the data is UTF-8 encoded.

(02-05-2021, 11:36 AM)Ahmed Sayed Wrote: What is the correct way to convert text with arabic letters to and from TStream using C++ builder Berlin?

Set the TIdHTTP.Request.ContentType property to 'text/json' or 'application/json', and set the TIdHTTP.Request.CharSet property to 'utf-8'.

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)