Ben
Ben

Reputation: 16524

How to send unicode characters in an HttpPost on Android

I'm trying to allow multilingual support in my app which makes an HTTP post to upload new messages. What do I need to do in order to support japanese & other non latin based languages? my code currently looks something like this:

    //note the msg string is a JSON message by the time it gets here...
private String doHttpPost(String url, String msg)
        throws Exception {

    HttpPost post = new HttpPost(url);

    StringEntity stringEntity = new StringEntity(msg);
    post.setEntity(stringEntity);


    return execute(post);
}

Upvotes: 15

Views: 9140

Answers (1)

Peter Knego
Peter Knego

Reputation: 80330

Try setting encoding on StringEntity:

StringEntity stringEntity = new StringEntity(msg, "UTF-8");

Upvotes: 40

Related Questions