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

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *