# Garbled code when using URLSubmit[] to request CJK web page

When importing content containing Chinese (CJK) characters, correct results can be obtained by using URLread

URLRead["https://zhuanlan.zhihu.com/p/35359905", "Body"]


But when using URLSubmit, the output is garbled

URLSubmit[
HTTPRequest["https://zhuanlan.zhihu.com/p/35359905",
CharacterEncoding -> "UTF-8"],
HandlerFunctions -> <|"BodyReceived" -> ((body = #Body) &)|>]


• It seems that the notion of "Body" is not consistent across different functions. URLRead's Body is already decoded with respect to response's headers, here ContentType->text/html; charset=utf-8. For URLSubmit is is raw string, so either use Jean-Pierre's answer or FromCharacterCode[ToCharacterCode@#Body, "UTF8"].
– Kuba
Jul 3 at 22:09
• @Kuba I can't run your code well ![jJCDIJ.png](imgtu.com/i/jJCDIJ) Jul 4 at 3:27

It appears that using BodyByteArray is the preferred approach.

URLSubmit[
HTTPRequest["https://zhuanlan.zhihu.com/p/35359905",
CharacterEncoding -> "UTF-8"],
HandlerFunctions -> <|

• It works because ByteArrayToString is "assuming it contains UTF-8 data", in general it could not be the case and decoding should be based on information in response's headers.