Android - Some UTF-8 characters get lost during HttpPost

Issue

Some non ASCII characters get lost when submitting HttpPost (or HttpPut) requests to a remote web service. All text after the problematic character also gets stripped out.
There were no issues on the server side as other clients could submit any non standard characters without any issues.

Resolution

The issue was caused by not specifying encoding in UrlEncodedFormEntity constructor. After setting encoding to "UTF-8", everything worked as expected.

 
httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
 

Android Studio 1.2
Android SDK 21

 

Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait