The biggest reason that characters are converted to question marks is the conversion of characters to bytes and then back to characters, rather than a match.
The code you supplied has the following line:
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
This is problematic because you did not specify how to convert bytes to characters. Instead, you probably want to:
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
What you specify for character encoding will depend on the character encoding you specify elsewhere. Without specifying a character encoding, you will get a default character encoding, and this depends on the settings on both the client and server. Java uses Unicode, and UTF-8 is the only encoding that retains all the characters that Java allows.
For debugging, you can use an InputStream and extract bytes from it, and also print the byte values โโto make sure that they are really UTF-8 encoded representations of the original characters. The correct encoding for "รถ" (x00F6) is "รยถ" (x00C3 x00B6).
You also need to make sure that the original POST request is encoded correctly in UTF-8 encoding. The UrlEncodedFormEntity class also uses the default character encoding, which may not be UTF-8. Change this:
UrlEncodedFormEntity uefe = new UrlEncodedFormEntity(nameValuePairList);
to
UrlEncodedFormEntity uefe = new UrlEncodedFormEntity(nameValuePairList, "UTF-8");
source share