`
coolerbaosi
  • 浏览: 729450 次
文章分类
社区版块
存档分类
最新评论

Android 与 HttpClient 通讯出现乱码问题的解决

 
阅读更多
Android 与 HttpClient 通讯出现乱码问题的解决

1、Android -> Http Server 组件,比如servlet.


第一种:在HttpEntity时提供编码,如:
HttpEntity entity = new UrlEncodedFormEntity(params,"GB2312");
第二种:在发送前对数据进行编码,如:
java.net.URLEncoder.encode(message,"GB2312");
服务器端接收时:
String message = new String (request.getParameter("message").getBytes("iso-8859-1"),"GB2312" )


2、Http Server 比如servlet -> Android

String message = "我的测试消息";
HttpServer 发送时:
message=new String(message.getBytes("GB2312"),"ISO-8859-1");
android 接收时:
message=new String(message.getBytes("ISO-8859-1"),"GB2312");
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics