如何在Android上的HttpPost中发送unicode字符

Ben*_*Ben 15 unicode post encoding android http

我正在尝试在我的应用中允许多语言支持,这使得HTTP帖子可以上传新消息.为了支持日语和其他非拉丁语言,我需要做什么?我的代码目前看起来像这样:

    //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);
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*ego 40

尝试在StringEntity上设置编码:

StringEntity stringEntity = new StringEntity(msg, "UTF-8");
Run Code Online (Sandbox Code Playgroud)