Graykos
Graykos

Reputation: 1311

EditText view encoding

In my application there are some kind of chat. When I receive message from server it displays well, but when I send message the text is all messed up. I suppose there are a problem with encoding, but how can I solve this? I already tried to setContentEncoding for postEntity, also I tried to encode string data with new String(old.getBytes("UTF-8")); Nothink helped.

Upvotes: 0

Views: 1268

Answers (1)

laalto
laalto

Reputation: 152867

I assume you're doing HTTP POST with Content-Type: multipart/form-data. Which library you use to generate the POST body data? If it's Apache httpmime, you'll need to pass an explicit CharSet parameter to your StringBody constructor, e.g.

CharSet cs = CharSet.defaultCharset();
MultipartEntity mp = new MultipartEntity();
mp.addPart("message", new StringBody("message to be encoded", cs));

If it's Content-Type: application/x-www-form-urlencoded, have a look at java.net.URLEncoder class.

Upvotes: 1

Related Questions