Android和javaweb通信中response.getHeader()乱码问题求破 android乱码javajavawebweb 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用的是GBKresponse.setCharacterEncoding("GBK"); 用的是GBKresponse.setCharacterEncoding("GBK");那你android端转下gbk啊 用的是GBKresponse.setCharacterEncoding("GBK");那你android端转下gbk啊Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();hello=new String(hello.getBytes("GBK"));System.out.println(hello);输出这样:还是乱码 这个问题 你只能自己多debug, 才能比较深的理解编码。现在编码格式基本上用utf-8 . 用的是GBKresponse.setCharacterEncoding("GBK");那你android端转下gbk啊Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();hello=new String(hello.getBytes("GBK"));System.out.println(hello);输出这样:还是乱码可能是这样new String(hello.getBytes("gbk"),"iso8859");可以先用浏览器试试 用的是GBKresponse.setCharacterEncoding("GBK");那你android端转下gbk啊Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();hello=new String(hello.getBytes("GBK"));System.out.println(hello);输出这样:还是乱码可能是这样new String(hello.getBytes("gbk"),"iso8859");可以先用浏览器试试Android端的中文还是问号,因为header关键字是自定义的,所以浏览器打不开,提示页面有错 问题没解决,不过我换另一种方式了。网上大多只给出Android端或JavaWeb端其中之一。在这里贴上两端的代码:首先是Android端//先准备要发送的数据HttpPost httpPost = new HttpPost(new URI(url));List<NameValuePair> list=new ArrayList<NameValuePair>();JSONObject jso=new JSONObject();jso.put("name", "abc大家好123");list.add(new BasicNameValuePair("info", jso.toString()));httpPost.setEntity(new UrlEncodedFormEntity(list, "GBK"));//然后连接HttpClient client = new DefaultHttpClient();HttpResponse response = client.execute(httpPost);//获取回送的数据if (response.getStatusLine().getStatusCode() == 200) {// 200表示请求成功 HttpEntity entity = response.getEntity(); if (entity != null) { String beanListToJson = EntityUtils.toString(entity, "GBK"); System.out.println("receive:"+beanListToJson); return beanListToJson; }}接下来JavaWeb端代码://获取Android提交的数据HttpServletRequest request = ServletActionContext.getRequest();String s=request.getParameter("info");System.out.println(s);//向Android发送数据HttpServletResponse response = ServletActionContext.getResponse();response.setCharacterEncoding("GBK");response.getWriter().write(beanListToJson);//这个beanListToJson是个处理过的json字符串 自己写的谷歌地图,老是出错我把我写的贴出来哈 android系统多线程,多任务下载问题! 谁给个飞机游戏源码,真机不卡顿的那种谢谢了!n_n android 复制的调用 android系统字体的问题 Cobub Razor问题 急!Android图片保存的问题 如何得知系统进入深度休眠或者从深度休眠中被唤醒? android界面中有多个按钮,有时候会发生阻塞 配置好的AVD启动之后出现以下代码,请问是怎么事? 有的apk用monkeyrunner安装不了 如何得知dialog显示位置发生变化
response.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
那你android端转下gbk啊
response.setCharacterEncoding("GBK");
那你android端转下gbk啊
Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();
hello=new String(hello.getBytes("GBK"));
System.out.println(hello);输出这样:
还是乱码
现在编码格式基本上用utf-8 .
response.setCharacterEncoding("GBK");
那你android端转下gbk啊
Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();
hello=new String(hello.getBytes("GBK"));
System.out.println(hello);输出这样:
还是乱码可能是这样new String(hello.getBytes("gbk"),"iso8859");
可以先用浏览器试试
response.setCharacterEncoding("GBK");
那你android端转下gbk啊
Android端改成这样么?String hello=response.getHeaders("hello")[0].getValue();
hello=new String(hello.getBytes("GBK"));
System.out.println(hello);输出这样:
还是乱码可能是这样new String(hello.getBytes("gbk"),"iso8859");
可以先用浏览器试试
Android端的中文还是问号,因为header关键字是自定义的,所以浏览器打不开,提示页面有错
首先是Android端//先准备要发送的数据
HttpPost httpPost = new HttpPost(new URI(url));
List<NameValuePair> list=new ArrayList<NameValuePair>();
JSONObject jso=new JSONObject();
jso.put("name", "abc大家好123");
list.add(new BasicNameValuePair("info", jso.toString()));
httpPost.setEntity(new UrlEncodedFormEntity(list, "GBK"));
//然后连接
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
//获取回送的数据
if (response.getStatusLine().getStatusCode() == 200) {// 200表示请求成功 HttpEntity entity = response.getEntity();
if (entity != null) {
String beanListToJson = EntityUtils.toString(entity, "GBK");
System.out.println("receive:"+beanListToJson);
return beanListToJson;
}
}
接下来JavaWeb端代码://获取Android提交的数据
HttpServletRequest request = ServletActionContext.getRequest();
String s=request.getParameter("info");
System.out.println(s);
//向Android发送数据
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("GBK");
response.getWriter().write(beanListToJson);//这个beanListToJson是个处理过的json字符串