When your Content-Type
header declares UTF-8 encoding, you must send UTF-8 encoded content.
Although browsers sometimes βguessβ or βfixβ the encoding, you should never rely on this, as it is a very fragile logic that often does not work properly.
If your Chinese / Japanese content was in a different encoding (e.g. Shift-JIS), you will have to convert the text to a library, such as iconv
.
Alternatively, you can declare this other encoding in the header, but note that you can only use one encoding for the entire response body. The best solution is to convert everything to UTF-8.
source share