HttpPost Entity时中文不识别问题

// 绑定到请求 Entry  
StringEntity se = new StringEntity(params.toString(),"UTF-8");
/* 
 *   for Encoding Test
System.out.println(params);
System.out.println(se);
System.out.println(EntityUtils.toString(se,"iso-8859-1"));
System.out.println(EntityUtils.toString(se,"gb2312"));
System.out.println(EntityUtils.toString(se,"gbk"));
System.out.println(EntityUtils.toString(se,"utf-8"));
*/
request.setEntity(se);  
// 发送请求  
HttpResponse httpResponse = new DefaultHttpClient().execute(request);  
// 得到应答的字符串,这也是一个 JSON 格式保存的数据  

String retSrc = EntityUtils.toString(httpResponse.getEntity()); 


通过StringEntity封好Json数据发送时候,将StringEntity se = new StringEntity(params.toString());

装好的数据中文都是?????

stringEntity.setContentEncoding("utf-8")------》这个没用!

后来new StringEntity中添加“UTF-8”编码设置,OK.............


你可能感兴趣的:(Android学习&开发)