How to send unicode characters in an HttpPost on A

2020-06-08 13:04发布

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);
}

1条回答
Deceive 欺骗
2楼-- · 2020-06-08 13:38

Try setting encoding on StringEntity:

StringEntity stringEntity = new StringEntity(msg, "UTF-8");
查看更多
登录 后发表回答