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

时间:2011-02-22 21:54:53

标签: android http unicode post encoding

我正在尝试在我的应用中允许多语言支持,这会使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);
}

1 个答案:

答案 0 :(得分:40)

尝试在StringEntity上设置编码:

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