码迷,mamicode.com
首页 > 其他好文 > 详细

POST中文转码问题

时间:2015-04-03 06:59:45      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:http   post   转码   

//在 new StringEntity(params, "utf-8")指定为utf-8编码
try {
HttpClient client = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(url);
//设置编码,防止中文传输乱码 
StringEntity entity = new StringEntity(contentValue.toString(), "utf-8");
httpPost.setEntity(entity);
HttpResponse response = client.execute(httpPost); 
//获取响应码
status = response.getStatusLine().getStatusCode();
//status = response.getStatusLine().getStatusCode();
Log.v("jsondata", "resp = " + response.getEntity().toString());
Log.v("jsondata", "status = " + status + "\n" + contentValue.toString());
}catch(Exception e){
Log.v("jsondata", "exception");
e.printStackTrace();
}

本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1627804

POST中文转码问题

标签:http   post   转码   

原文地址:http://670176656.blog.51cto.com/4500575/1627804

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!