如何在HttpPost Android上发单code字 [英] How to send unicode characters in an HttpPost on Android
本文介绍了如何在HttpPost Android上发单code字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让我的应用程序,这使得一个HTTP POST上传新的消息的多语言支持。什么我需要做的,为了支持日本和放大器;其他非拉丁语系语言?我的code目前看起来是这样的:
//注意味精字符串是由它送过来的时候一个JSON消息...
私人字符串doHttpPost(URL字符串,字符串味精)
抛出异常{
HttpPost后=新HttpPost(URL);
StringEntity stringEntity =新StringEntity(MSG);
post.setEntity(stringEntity);
返回执行(后);
}
解决方案
尝试在StringEntity设置编码:
StringEntity stringEntity =新StringEntity(MSG,UTF-8);
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);
}
解决方案
Try setting encoding on StringEntity:
StringEntity stringEntity = new StringEntity(msg, "UTF-8");
这篇关于如何在HttpPost Android上发单code字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文