您的位置:首页 > 移动开发 > Android开发

android url 中文请求,乱码解决

2013-05-25 14:30 381 查看
private String connServerForResult(String url) {
String strResult = "";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost();
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setURI(new URI(url));
//httpPost,通过urlParam添加请求参数
List < NameValuePair > urlParam = new ArrayList < NameValuePair > ();

//中文内容,通过URLDecoder.decode转码
urlParam.add(new BasicNameValuePair("date", URLDecoder.decode(date_search.getText().toString(), "utf-8")));
httpPost.setEntity(new UrlEncodedFormEntity(urlParam, HTTP.UTF_8));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null)
strResult = EntityUtils.toString(entity, HTTP.UTF_8);

} catch (Exception e) {
//
}
return strResult;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: