Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 884
Ben Avatar asked Feb 22 '11 21:02

Ben


1 Answers

Try setting encoding on StringEntity:

StringEntity stringEntity = new StringEntity(msg, "UTF-8");
like image 55
Peter Knego Avatar answered Oct 23 '22 23:10

Peter Knego