加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Android 与 HttpClient 通讯出现乱码问题的处理

发布时间:2021-11-24 20:40:05 所属栏目:教程 来源:互联网
导读:Android 与 HttpClient 通讯出现乱码问题的解决 1、Android - Http Server 组件,比如servlet. 第一种:在HttpEntity时提供编码,如: HttpEntity entity = new UrlEncodedFormEntity(params,GB2312); 第二种:在发送前对数据进行编码,如: java.net.URLEnc

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");

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读