如何在Android中使用HttpPost发送Unicode字符

15

我正在尝试为我的应用程序启用多语言支持,该应用程序使用HTTP post上传新消息。为了支持日语和其他非拉丁语系的语言,我需要做什么? 我当前的代码大致如下:

    //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个回答

40

尝试在 StringEntity 上设置编码:

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

我有同样的问题,你能帮我吗? - Mahdi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接